Skip to main content

Configuration ORM for Python apps

Project description

Configuration ORM for Python applications

Test Status

A python library which provides ORM like semantics to application configuration. At present, it provides the expected functionality but requires some more work in terms of error handling.

The library works on the concept of configuration sources. Currently following sources are supported,

User defines a application settings schema by subclassing from ConfigSchema class. User can choose one or more configuration sources to create a Pydantic object based on application configuration schema.

Library will then try to read from all provided configuration sources and merge them to build the pydantic application configuration object.

Important Note

Name of keys in configuration sources and confguration schema MUST match. It would have been nice to decouple two, but for the intended functionality, it's a minor enhancement.

Configuration sources are provided as a list of objects and precedence and priority of sources is determined by ordering of the sources in the list, e.g. first source in the list has lowest precendence, last one has the highest.

Read-Write Capability

If the configuration supports, library provides ability to save functionality for the application configuration object. By default, write capability is disabled.

Configuration Source Read Read-Write
TOML Yes Yes
JSON Yes Yes
YAML Yes Yes
DotEnv Yes No
Environment Variable Yes Yes

Example

Using JSON

{
    "Service": {
        "Host": "localhost",
        "Port": 18080
    },
}

Using TOML

[Service]
Host = "localhost",
Port = 18080

Using YAML

Service:
    Host: "localhost"
    Port: 18080

Using DotEnv files / Environment variables

CFGORM_SERVICE__HOST=localhost
CFGORM_SERVICE__PORT=8080
class TestServiceConfig(BaseModel):
    Host: str = Field(..., description="Host running the service")
    Port: int = Field(..., description="Port bound to the service")


class TestConfig(ConfigSchema):
    Service: TestServiceConfig = Field(..., description="Service configuration")

json_source = JSONSource(file_path=Path(config_file_json))

cfg_orm = ConfigORM(schema=TestConfig, sources=[json_source])

cfg: TestConfig = cfg_orm.load_config()

print(cfg)

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

py_configorm-0.1.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

py_configorm-0.1.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file py_configorm-0.1.1.tar.gz.

File metadata

  • Download URL: py_configorm-0.1.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/24.0.0

File hashes

Hashes for py_configorm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3c31bc2a95dc006f635fb1984a2585c7f052c117c12016d8d63f6177d08a8101
MD5 24c3c118725c2bbb3c25f7d2f4a9515b
BLAKE2b-256 26256e060ef854caa3153d053b9ca0ceae566c06502a6350c20e0db1d8caf6fd

See more details on using hashes here.

File details

Details for the file py_configorm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py_configorm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/24.0.0

File hashes

Hashes for py_configorm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 66f58f4d80aac79214a143a87d1d4f7985c374664b80b375a79e88633992379a
MD5 64218a7909c81ea3593023f14df32dc2
BLAKE2b-256 0dead8786ec8ab63c1ad2149d0604d11ba127c3574545c2437d5c0eb230ae581

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