Skip to main content

dataclassconfig

License Version Python versions Code style: black

The simplest interface for working with configuration files. Describe the structure of your configuration file as a dataclass. Use inheritance and composition to describe the complex hierarchical structure of a configuration file.

Installation

pip install dataclassconfig

Requirements

Minimum Python version supported by dataclassconfig is 3.6

Usage

Describe the structure of your config file like a dataclass and inherit it from Сonfig

from dataclassconfig import Config

class Socket(Config):
    host: str
    port: int

class DatabaseConnection(Socket):
    database: str
    username: str
    password: str

class ServerConfig(Config):
    root: str
    db: DatabaseConnection

Create a configuration file according to the described structure in YML or JSON format

# server-config.yml
root: ~/server
db:
  host: localhost
  port: 1234
  database: database
  username: demouser
  password: demopassword
// server-config.json
{
    "root": "~/server",
    "db": {
        "host": "localhost",
        "port": 1234,
        "database": "database",
        "username": "demouser",
        "password": "demopassword",
    },
}

Load the config file using your class

config = ServerConfig.load("server-config.yml")

or

config = ServerConfig.load("server-config.json")

The load method will check the completeness of the provided data in the configuration file and strictly match the data types. The result will be the same in both cases, the config object contains fields defined in the class

config :- ServerConfig(
    root='~/server',
    db=DatabaseConnection(
        host='localhost',
        port=1234,
        database='database',
        username='demouser',
        password='demopassword'
    )
)

config.db.username :- 'demouser'

Gratitude

This module works thanks to the implementation in the dacite project

Authors

Created by Vladislav A. Proskurov

Metadata

Release files for dataclassconfig 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dataclassconfig 0.0.3
File Size Uploaded Provenance Actions
dataclassconfig-0.0.3.tar.gz 4.2 kB Without provenance Details for dataclassconfig-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dataclassconfig 0.0.3
File Interpreter ABI Platform Actions
dataclassconfig-0.0.3-py3-none-any.whl Python 3 none any Details for dataclassconfig-0.0.3-py3-none-any.whl

Total release size: 8.9 kB

Release files / dataclassconfig-0.0.3.tar.gz

Download URL dataclassconfig-0.0.3.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
09e67026e2aca3baca3f1aa176fc3b85c3f166a0d5e3f443b7aa02b097d41d0b
BLAKE2b-256 checksum
How to use checksums
cb3a36a3e47721fa837de9ebb489fe1cfa380a2771a22efc2c49359ec12cc701
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.13

Release files / dataclassconfig-0.0.3-py3-none-any.whl

Download URL dataclassconfig-0.0.3-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1cd56e835f7bee6a788e1fb3589c8fd88ac7866d066f146ba13940dcfd9dd3b1
BLAKE2b-256 checksum
How to use checksums
f15b25049849882682b596e04c12a8ba26ff65753eb7eb5f8e5cad8fb6c8d7db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.13

Security for dataclassconfig 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page