Manage python application config with ease.
Project description
quicksettings
A zero dependency package to manage python application configuration.
Installation
pip install quicksettings
Getting started
from dataclasses import InitVar, dataclass
from quicksettings import BaseSettings
@dataclass(init=False)
class Settings(BaseSettings):
env_prefix: InitVar[str] = "FOO_"
USERNAME: str
PASSWORD: str = "slightly-secret"
settings = Settings()
The snippet above will set the value of settings.USERNAME to the value of the FOO_USERNAME environment variable.
settings.PASSWORD will default to the supplied value if the related environment variable is not set. Thus, environment variables take precedence over defaults.
If fields with no defaults are declared without corresponding environment variables, an exception will be raised.
Supported field types
strintfloatboolEnumlistdict
New in v1.1.0
- Other dataclasses
Example environment:
export POWER_SOURCES='[{"name":"coal","output": 20},{"name":"nuclear","output": 10000}]'
from dataclasses import dataclass, is_dataclass
from quicksettings import BaseSettings
@dataclass
class PowerSource:
name: str
output: int
@dataclass(init=False)
class Settings(BaseSettings):
POWER_SOURCES: list[PowerSource]
settings = Settings()
assert is_dataclass(settings.POWER_SOURCES[0]) # True
assert settings.POWER_SOURCES[1].name == "nuclear" # True
Known limitations
- Since we're working with vanilla dataclasses, values with defaults cannot be defined before values without defaults. If your application is running python >= 3.10, the dataclass
kw_onlyarg can be supplied. - No dotenv support - it's up to you to set up the environment.
- Field names are case sensitive by default
- Union field types other than
<type> | Nonewill raise an exception
Project details
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 quicksettings-1.1.1.tar.gz.
File metadata
- Download URL: quicksettings-1.1.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaffe07e7cd860e5b1487bff8bef693259210750dd5160ce8b5466d3eb8d6a86
|
|
| MD5 |
b9570c010c50695cd0f4ab681524c5c6
|
|
| BLAKE2b-256 |
fbb74840f477e803f6271d719f7631785c7962b57d555782a19492b8f90cb5e9
|
File details
Details for the file quicksettings-1.1.1-py3-none-any.whl.
File metadata
- Download URL: quicksettings-1.1.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9218a696f1c1ae0ca2255c62f5a69608359e752a5de83930917e2ffe167c7fb
|
|
| MD5 |
d6df060c2a694281bf9fa704277e5d62
|
|
| BLAKE2b-256 |
5b9de1c10f35d87103fd6942ccecf5cd78891a698982d16f158348279ae553c6
|