No project description provided
Project description
Dynaconf Tortoise ORM Loader
Installation
pip install dynaconf-tortoise-loader
By default, Tortoise ORM comes with a sqlite database driver.
If you require a different database driver, please refer to the Tortoise ORM documentation.
Usage
-
Create a config.py file in your project
import logging from pathlib import Path from typing import Any from dynaconf import Dynaconf, ValidationError from dynaconf.utils.boxing import DynaBox from dynaconf.utils.functional import empty from dynaconf_tortoise_loader import loader _BASE_DIR = Path.cwd() _DB_PATH = _BASE_DIR / "data" / "settings.sqlite3" class Config(Dynaconf): def __init__(self, *args: Any, **kwargs: Any) -> None: super().__init__(*args, **kwargs) self._initialized = True def __setattr__(self, name: str, value: Any) -> None: if name not in [ "_wrapped", "_kwargs", "_warn_dynaconf_global_settings", ]: if self._wrapped is empty: self._setup() super().__setattr__(name, value) if hasattr(self, "_initialized") and self._initialized: try: data = DynaBox({name: value}, box_settings={}).to_dict() loader.write(self, data) except Exception as e: logging.error(e) settings = Config( # Define the environments to use # environments=True, envvar_prefix="MYAPP", settings_files=[ _BASE_DIR / "settings.toml", _BASE_DIR / ".secrets.toml", ], LOADERS_FOR_DYNACONF=[ "dynaconf_tortoise_loader.loader", # require custom loader "dynaconf.loaders.env_loader", # require dotenv loader ], TORTOISE_ENABLED_FOR_DYNACONF=True, TORTOISE_URL_FOR_DYNACONF=f"sqlite://{_DB_PATH}", ) try: settings.validators.validate_all() except ValidationError as e: logging.error(e.message)
The
TORTOISE_URL_FOR_DYNACONFvalue must contain the database connection string. See the Tortoise ORM documentation for more details.TORTOISE_URL_FOR_DYNACONFdoes not need to be declared directly in the code, but can be declared in the settings files listed insettings_filesor set via an environment variable. For more information, please refer to the Dynaconf documentation. -
Use the
settingsobject in your codeform .config import settings # set and store settings settings.host = "localhost" settings.port = 8022 # get settings print(settings.get("host")) print(settings.get("port"))
See more example
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dynaconf_tortoise_loader-0.1.0.tar.gz.
File metadata
- Download URL: dynaconf_tortoise_loader-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91e2d5a2227ad18847ca50e9e795d2b8f9214b1131c073dea3a55d815fe69e7c
|
|
| MD5 |
c74ef45ebaa7968867719f5f2781ec32
|
|
| BLAKE2b-256 |
3e3dba2bcee3d02637efa7d7965c6a6d8d58bdeb002c22d0bc1fca33b6213062
|
File details
Details for the file dynaconf_tortoise_loader-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dynaconf_tortoise_loader-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
022bb352d526046b3a3241d20d314e605ff20af371c271c0f01fc5be045c4e9c
|
|
| MD5 |
be2c1861f81eabb8149976409830c1e2
|
|
| BLAKE2b-256 |
3402c5b83350f7479f5b26a7593c0d96cb44696aed472da0dcedaeed5f503af1
|