Configuring MGnipyConfig#
What is mgnipy.MGnipyConfig?#
A Pydantic-based settings object used across MGni.Py to:
✅ store API connection details such as the base url
✅ store credentials (
mg_user,mg_password) and handle retrieval and verification of sliding authentication tokens (auth_token)✅ and configure the cache such as local disk cache directory (
cache_dir).
The fields#
cache_dir: Directory used for response caching; defaults to a platform-appropriate cache directory viaplatformdirs. Set toNoneto disable disk caching.mg_user/mg_password: Optional MGnify username/password for sliding-token authentication.api_version: Which API version to target (Should be: v2).base_url: Base MGnify URL. Should be:https://www.ebi.ac.uk/.
Authentication#
mgnipy.MGnipyConfig takes care of
Checking for cached sliding JSON Web Tokens (JWT) which comprises a shorter-lived Access token and a longer Refresh token.
Verifying the validity of Access tokens using the token_verify endpoint
Refreshing access, getting a new Access token if the Refresh token is at least still valid using token_refresh_sliding
Or obtaining new Access and Refresh tokens using login credentials (e.g., like from a .env file) from the token_obtain_sliding endpoint of the MGnify API using your username/password
Caching the token and stored in
MGnipyConfig.auth_tokenfor the session and used for authenticated API requests.
Note
By default the token is cached on disk under a platform-appropriate cache dir (via
platformdirs) in a file named auth_.json. – unless cache is disabled via cache_dir=NoneCached tokens are stored per base URL + username (hashed) to avoid collisions when using multiple endpoints/accounts.
See accessing private data page on how to configure for private data.