Skip to main content

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

  • str
  • int
  • float
  • bool
  • Enum
  • list
  • dict

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_only arg 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> | None will 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

quicksettings-1.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quicksettings-1.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file quicksettings-1.1.0.tar.gz.

File metadata

  • Download URL: quicksettings-1.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for quicksettings-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0fd49ea67e63a8dc52df0f829c5f1c39567c176eecbe630ecc138726359e761c
MD5 842b2da47c9ba15e3f51a9a5ea4dab31
BLAKE2b-256 721fea571af6716a6f298a594c8c3388e6134302337e910e55f44a3d8b5e1091

See more details on using hashes here.

File details

Details for the file quicksettings-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: quicksettings-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for quicksettings-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f3d86511322907dfbfe075a821513e4b5379829bf0bcee6abb8e5b1b01b5e70
MD5 f294c8ef1b2784d5a9514ad9dcb3a782
BLAKE2b-256 be4a0a1e09d0fbb638ddd8acce5ec4295d6770a8cf9822b3f530d774a637101c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page