Catalog PyPI
PACKAGE EXPLORERView in registry

12factor-configclasses

PyPI

Like dataclasses but for config.

Versions collected1
Direct dependencies3From release 2.0.1
Last observed20 Oct, 15:12 UTC

README

Version 2.0.1 documentation

configclasses

PyPI codecov Downloads Downloads

Like dataclasses but for config.

Specify your config with a class and load it with your env vars or env files.

# .env
HOST=0.0.0.0
PORT=8000
...
import httpx
from configclasses import configclass


@configclass
class ClientConfig:
    host: str
    port: int


class UserAPIClient(httpx.AsyncClient):
    def __init__(self, config: ClientConfig, *args, **kwargs):
        self.config = config
        ...
        

config = ClientConfig.from_path(".env")
async with UserAPIClient(config) as client:
    ...

Features

  • Fill your configclasses with existent env vars.
  • Define default values in case these variables have no value at all.
  • Load your config files in env vars following 12factor apps recommendations.
  • Support for .env, yaml, toml, ini and json.
  • Convert your env vars with specified type in configclass: int, float, str or bool.
  • Use nested configclasses to more complex configurations.
  • Specify a prefix with @configclass(prefix="<PREFIX>") to append this prefix to your configclass' attribute names.
  • Config groups (TODO): https://cli.dev/docs/tutorial/config_groups/

Requirements

Python 3.8+

Installation

Depending on your chosen config file format you can install:

  • .env -> pip install 12factor-configclasses[dotenv]
  • .yaml -> pip install 12factor-configclasses[yaml]
  • .toml -> pip install 12factor-configclasses[toml]
  • .ini -> pip install 12factor-configclasses
  • .json -> pip install 12factor-configclasses

Or install all supported formats with:

pip install 12factor-configclasses[full]

Usage

There are three ways to use it.

Loading an .env file:

# .env
HOST=0.0.0.0
PORT=8000
DB_URL=sqlite://:memory:
GENERATE_SCHEMAS=True
DEBUG=True
HTTPS_ONLY=False
GZIP=True
SENTRY=False
#config.py
from configclasses import configclass


@configclass
class DB:
    user: str
    password: str
    url: str


@configclass
class AppConfig:
    host: str
    port: int
    db: DB
    generate_schemas: bool
    debug: bool
    https_only: bool
    gzip: bool
    sentry: bool
# app.py
from api.config import AppConfig

app_config = AppConfig.from_path(".env")
app = Starlette(debug=app_config.debug)

if app_config.https_only:
    app.add_middleware(
        HTTPSRedirectMiddleware)
if app_config.gzip:
    app.add_middleware(GZipMiddleware)
if app_config.sentry:
    app.add_middleware(SentryAsgiMiddleware)

...

register_tortoise(
    app,
    db_url=app_config.db.url,
    modules={"models": ["api.models"]},
    generate_schemas=app_config.generate_schemas,
)

if __name__ == "__main__":
    uvicorn.run(app, host=app_config.host, port=app_config.port)

Loading predefined environmental variables:

The same than before, but instead of:

app_config = AppConfig.from_path(".env")

You will do:

app_config = AppConfig.from_environ()

Loading a file from a string:

test_env = """HOST=0.0.0.0
PORT=8000
DB_URL=sqlite://:memory:
GENERATE_SCHEMAS=True
DEBUG=True
HTTPS_ONLY=False
GZIP=True
SENTRY=False"""
app_config = AppConfig.from_string(test_env, ".env")

Downloads & popularity

5downloads
1-day window · source-reported counts19 Oct 2026
11557.50
2026-07-22: 19 · observed 2026-10-20T17:55:47.0496303Z · period 2026-07-22–2026-07-222026-07-23: 21 · observed 2026-10-20T17:55:47.0496303Z · period 2026-07-23–2026-07-232026-07-24: 36 · observed 2026-10-20T17:55:47.0496303Z · period 2026-07-24–2026-07-242026-07-25: 2 · observed 2026-10-20T17:55:47.0496303Z · period 2026-07-25–2026-07-252026-07-27: 33 · observed 2026-10-20T17:55:47.0496303Z · period 2026-07-27–2026-07-272026-07-28: 30 · observed 2026-10-20T17:55:47.0496303Z · period 2026-07-28–2026-07-282026-07-29: 49 · observed 2026-10-20T17:55:47.0496303Z · period 2026-07-29–2026-07-292026-07-30: 51 · observed 2026-10-20T17:55:47.0496303Z · period 2026-07-30–2026-07-302026-07-31: 30 · observed 2026-10-20T17:55:47.0496303Z · period 2026-07-31–2026-07-312026-08-01: 7 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-01–2026-08-012026-08-02: 3 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-02–2026-08-022026-08-03: 45 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-03–2026-08-032026-08-04: 28 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-04–2026-08-042026-08-05: 14 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-05–2026-08-052026-08-06: 39 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-06–2026-08-062026-08-07: 25 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-07–2026-08-072026-08-08: 11 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-08–2026-08-082026-08-09: 19 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-09–2026-08-092026-08-10: 16 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-10–2026-08-102026-08-11: 33 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-11–2026-08-112026-08-12: 15 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-12–2026-08-122026-08-13: 29 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-13–2026-08-132026-08-14: 62 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-14–2026-08-142026-08-15: 6 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-15–2026-08-152026-08-16: 2 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-16–2026-08-162026-08-17: 42 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-17–2026-08-172026-08-18: 115 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-18–2026-08-182026-08-19: 17 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-19–2026-08-192026-08-20: 14 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-20–2026-08-202026-08-21: 36 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-21–2026-08-212026-08-22: 11 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-22–2026-08-222026-08-23: 13 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-23–2026-08-232026-08-24: 29 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-24–2026-08-242026-08-25: 20 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-25–2026-08-252026-08-26: 33 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-26–2026-08-262026-08-27: 15 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-27–2026-08-272026-08-28: 28 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-28–2026-08-282026-08-29: 10 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-29–2026-08-292026-08-31: 19 · observed 2026-10-20T17:55:47.0496303Z · period 2026-08-31–2026-08-312026-09-01: 36 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-01–2026-09-012026-09-02: 48 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-02–2026-09-022026-09-03: 27 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-03–2026-09-032026-09-04: 34 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-04–2026-09-042026-09-05: 4 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-05–2026-09-052026-09-06: 2 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-06–2026-09-062026-09-07: 8 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-07–2026-09-072026-09-08: 9 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-08–2026-09-082026-09-09: 4 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-09–2026-09-092026-09-10: 17 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-10–2026-09-102026-09-11: 17 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-11–2026-09-112026-09-12: 14 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-12–2026-09-122026-09-13: 5 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-13–2026-09-132026-09-14: 14 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-14–2026-09-142026-09-15: 19 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-15–2026-09-152026-09-16: 21 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-16–2026-09-162026-09-17: 18 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-17–2026-09-172026-09-18: 13 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-18–2026-09-182026-09-19: 1 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-19–2026-09-192026-09-20: 36 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-20–2026-09-202026-09-21: 31 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-21–2026-09-212026-09-22: 17 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-22–2026-09-222026-09-23: 16 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-23–2026-09-232026-09-24: 54 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-24–2026-09-242026-09-25: 51 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-25–2026-09-252026-09-26: 44 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-26–2026-09-262026-09-27: 9 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-27–2026-09-272026-09-28: 45 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-28–2026-09-282026-09-29: 32 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-29–2026-09-292026-09-30: 15 · observed 2026-10-20T17:55:47.0496303Z · period 2026-09-30–2026-09-302026-10-01: 11 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-01–2026-10-012026-10-02: 15 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-02–2026-10-022026-10-05: 1 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-05–2026-10-052026-10-06: 15 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-06–2026-10-062026-10-07: 4 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-07–2026-10-072026-10-08: 8 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-08–2026-10-082026-10-09: 74 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-09–2026-10-092026-10-10: 8 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-10–2026-10-102026-10-11: 5 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-11–2026-10-112026-10-12: 15 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-12–2026-10-122026-10-13: 5 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-13–2026-10-132026-10-14: 14 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-14–2026-10-142026-10-15: 16 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-15–2026-10-152026-10-16: 24 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-16–2026-10-162026-10-17: 11 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-17–2026-10-172026-10-18: 4 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-18–2026-10-182026-10-19: 5 · observed 2026-10-20T17:55:47.0496303Z · period 2026-10-19–2026-10-19
22 Jul19 Oct

pypistats · 86 observations shown. Missing days are unknown. Source category: overall: without mirrors.

View observed values
Date / source periodValueObserved at
2026-10-19 – 2026-10-1952026-10-20T17:55:47.0496303Z
2026-10-18 – 2026-10-1842026-10-20T17:55:47.0496303Z
2026-10-17 – 2026-10-17112026-10-20T17:55:47.0496303Z
2026-10-16 – 2026-10-16242026-10-20T17:55:47.0496303Z
2026-10-15 – 2026-10-15162026-10-20T17:55:47.0496303Z
2026-10-14 – 2026-10-14142026-10-20T17:55:47.0496303Z
2026-10-13 – 2026-10-1352026-10-20T17:55:47.0496303Z
2026-10-12 – 2026-10-12152026-10-20T17:55:47.0496303Z
2026-10-11 – 2026-10-1152026-10-20T17:55:47.0496303Z
2026-10-10 – 2026-10-1082026-10-20T17:55:47.0496303Z
2026-10-09 – 2026-10-09742026-10-20T17:55:47.0496303Z
2026-10-08 – 2026-10-0882026-10-20T17:55:47.0496303Z
2026-10-07 – 2026-10-0742026-10-20T17:55:47.0496303Z
2026-10-06 – 2026-10-06152026-10-20T17:55:47.0496303Z
2026-10-05 – 2026-10-0512026-10-20T17:55:47.0496303Z
2026-10-02 – 2026-10-02152026-10-20T17:55:47.0496303Z
2026-10-01 – 2026-10-01112026-10-20T17:55:47.0496303Z
2026-09-30 – 2026-09-30152026-10-20T17:55:47.0496303Z
2026-09-29 – 2026-09-29322026-10-20T17:55:47.0496303Z
2026-09-28 – 2026-09-28452026-10-20T17:55:47.0496303Z
2026-09-27 – 2026-09-2792026-10-20T17:55:47.0496303Z
2026-09-26 – 2026-09-26442026-10-20T17:55:47.0496303Z
2026-09-25 – 2026-09-25512026-10-20T17:55:47.0496303Z
2026-09-24 – 2026-09-24542026-10-20T17:55:47.0496303Z
2026-09-23 – 2026-09-23162026-10-20T17:55:47.0496303Z
2026-09-22 – 2026-09-22172026-10-20T17:55:47.0496303Z
2026-09-21 – 2026-09-21312026-10-20T17:55:47.0496303Z
2026-09-20 – 2026-09-20362026-10-20T17:55:47.0496303Z
2026-09-19 – 2026-09-1912026-10-20T17:55:47.0496303Z
2026-09-18 – 2026-09-18132026-10-20T17:55:47.0496303Z
2026-09-17 – 2026-09-17182026-10-20T17:55:47.0496303Z
2026-09-16 – 2026-09-16212026-10-20T17:55:47.0496303Z
2026-09-15 – 2026-09-15192026-10-20T17:55:47.0496303Z
2026-09-14 – 2026-09-14142026-10-20T17:55:47.0496303Z
2026-09-13 – 2026-09-1352026-10-20T17:55:47.0496303Z
2026-09-12 – 2026-09-12142026-10-20T17:55:47.0496303Z
2026-09-11 – 2026-09-11172026-10-20T17:55:47.0496303Z
2026-09-10 – 2026-09-10172026-10-20T17:55:47.0496303Z
2026-09-09 – 2026-09-0942026-10-20T17:55:47.0496303Z
2026-09-08 – 2026-09-0892026-10-20T17:55:47.0496303Z
2026-09-07 – 2026-09-0782026-10-20T17:55:47.0496303Z
2026-09-06 – 2026-09-0622026-10-20T17:55:47.0496303Z
2026-09-05 – 2026-09-0542026-10-20T17:55:47.0496303Z
2026-09-04 – 2026-09-04342026-10-20T17:55:47.0496303Z
2026-09-03 – 2026-09-03272026-10-20T17:55:47.0496303Z
2026-09-02 – 2026-09-02482026-10-20T17:55:47.0496303Z
2026-09-01 – 2026-09-01362026-10-20T17:55:47.0496303Z
2026-08-31 – 2026-08-31192026-10-20T17:55:47.0496303Z
2026-08-29 – 2026-08-29102026-10-20T17:55:47.0496303Z
2026-08-28 – 2026-08-28282026-10-20T17:55:47.0496303Z
2026-08-27 – 2026-08-27152026-10-20T17:55:47.0496303Z
2026-08-26 – 2026-08-26332026-10-20T17:55:47.0496303Z
2026-08-25 – 2026-08-25202026-10-20T17:55:47.0496303Z
2026-08-24 – 2026-08-24292026-10-20T17:55:47.0496303Z
2026-08-23 – 2026-08-23132026-10-20T17:55:47.0496303Z
2026-08-22 – 2026-08-22112026-10-20T17:55:47.0496303Z
2026-08-21 – 2026-08-21362026-10-20T17:55:47.0496303Z
2026-08-20 – 2026-08-20142026-10-20T17:55:47.0496303Z
2026-08-19 – 2026-08-19172026-10-20T17:55:47.0496303Z
2026-08-18 – 2026-08-181152026-10-20T17:55:47.0496303Z
2026-08-17 – 2026-08-17422026-10-20T17:55:47.0496303Z
2026-08-16 – 2026-08-1622026-10-20T17:55:47.0496303Z
2026-08-15 – 2026-08-1562026-10-20T17:55:47.0496303Z
2026-08-14 – 2026-08-14622026-10-20T17:55:47.0496303Z
2026-08-13 – 2026-08-13292026-10-20T17:55:47.0496303Z
2026-08-12 – 2026-08-12152026-10-20T17:55:47.0496303Z
2026-08-11 – 2026-08-11332026-10-20T17:55:47.0496303Z
2026-08-10 – 2026-08-10162026-10-20T17:55:47.0496303Z
2026-08-09 – 2026-08-09192026-10-20T17:55:47.0496303Z
2026-08-08 – 2026-08-08112026-10-20T17:55:47.0496303Z
2026-08-07 – 2026-08-07252026-10-20T17:55:47.0496303Z
2026-08-06 – 2026-08-06392026-10-20T17:55:47.0496303Z
2026-08-05 – 2026-08-05142026-10-20T17:55:47.0496303Z
2026-08-04 – 2026-08-04282026-10-20T17:55:47.0496303Z
2026-08-03 – 2026-08-03452026-10-20T17:55:47.0496303Z
2026-08-02 – 2026-08-0232026-10-20T17:55:47.0496303Z
2026-08-01 – 2026-08-0172026-10-20T17:55:47.0496303Z
2026-07-31 – 2026-07-31302026-10-20T17:55:47.0496303Z
2026-07-30 – 2026-07-30512026-10-20T17:55:47.0496303Z
2026-07-29 – 2026-07-29492026-10-20T17:55:47.0496303Z
2026-07-28 – 2026-07-28302026-10-20T17:55:47.0496303Z
2026-07-27 – 2026-07-27332026-10-20T17:55:47.0496303Z
2026-07-25 – 2026-07-2522026-10-20T17:55:47.0496303Z
2026-07-24 – 2026-07-24362026-10-20T17:55:47.0496303Z
2026-07-23 – 2026-07-23212026-10-20T17:55:47.0496303Z
2026-07-22 – 2026-07-22192026-10-20T17:55:47.0496303Z

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
2.0.118 Oct 20233

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
kingoodie/configclasses

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 15:12 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:1d2fe21a7454d4b14cbc1b4e68079a3afb1f86da5cc8c321c3fb06783ceb0363