refactor: extract MdrsClient service layer for library portability

To improve the tool's portability as a Python library, the core logic
has been decoupled from the CLI interface. This allows developers to
programmatically interact with MDRS without relying on CLI-specific
argument parsing or local file-based caches.

- Introduce `MdrsClient` service layer to handle core operations.
- Abstract authentication state using `CacheInterface` and `InMemoryCache`.
- Migrate all CLI commands to utilize `MdrsClient` for execution.
- Separate `Doi` data model from API responses and move to `models/doi.py`.
- Update `README.md` to include Python API usage examples.
- Bump package version to 1.3.17.
This commit is contained in:
2026-07-02 13:07:18 +09:00
parent 809140dfbc
commit 36cad6db52
28 changed files with 736 additions and 215 deletions
+4 -4
View File
@@ -9,7 +9,7 @@ from requests_toolbelt.multipart.encoder import MultipartEncoder
from typing_extensions import Unpack
from mdrsclient.__version__ import __version__
from mdrsclient.cache import CacheFile
from mdrsclient.cache import CacheFile, CacheInterface
from mdrsclient.exceptions import MissingConfigurationException
from mdrsclient.models import Laboratories, Token, User
@@ -39,14 +39,14 @@ class MDRSConnection:
url: str
session: Session
lock: threading.Lock
__cache: CacheFile
__cache: CacheInterface
def __init__(self, remote: str, url: str) -> None:
def __init__(self, remote: str, url: str, cache: CacheInterface | None = None) -> None:
super().__init__()
self.url = url
self.session = Session()
self.lock = threading.Lock()
self.__cache = CacheFile(remote)
self.__cache = cache if cache is not None else CacheFile(remote)
self.__prepare_headers()
def get(self, url: str, **kwargs: Unpack[_KwArgsMDRSConnectionGet]) -> Response: