Skip to main content

Easy Yaml based Configuration for Python

Project description

EYConf

Easy Yaml based Configuration for Python

build status docs License: GPL v3

Features

  • Generate: Automatically convert a schema to a yaml configuration file, including comments!
  • Validate: Validate a given configuration file against your schema and raise human readable errors!
  • Extend: Introduce custom logic by extending the EYConf class!
  • Reload: Reload your configuration on the fly without restarting your application!

Installation

You can install EYConf from PyPI using pip.

pip install eyconf

Quickstart

First of define a configuration schema using dataclasses.

from dataclasses import dataclass
from typing import Optional

@dataclass
class Transport:
    """Email transport configuration"""
    host: str = 'imap.example.com'
    port: int = 993
    username: str = 'user'
    password: str = 'password'
    use_ssl: bool = False

@dataclass
class Other:
    """Other configuration options"""
    bar: Optional[int]

@dataclass
class ConfigSchema:
    """My configuration schema

    Docstrings are used as comments in the generated yaml file!
    """
    transport: Transport
    other: Other

We can now create a configuration using the EYConf class directly, if you need more control it is also possible to extend the class.

# Using create_config_class helper function
from eyconf import EYConf

config = EYConf(ConfigSchema,'config.yaml')

This created the config.yaml file in your current working directory with the following content. Notice that the docstrings are used as comments in the generated yaml file.

# My configuration schema
# Docstrings are used as comments in the generated yaml file!

transport:
  # Email transport configuration

  host: imap.example.com
  port: 993
  username: user
  password: password
  use_ssl: false

other:
  # Other configuration options

  bar: null

You can access your configuration directly as attributes of the config object.

assert type(config.transport) == Transport
assert config.transport.host == "imap.example.com"

If you want to change the configuration, you can do so by editing the config.yaml file directly and reloading the configuration.

...
transport:
  host: changed.example.com
config.refresh()
assert config.transport.host == "changed.example.com"

For more information, please refer to the documentation.

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

eyconf-0.0.5.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

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

eyconf-0.0.5-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file eyconf-0.0.5.tar.gz.

File metadata

  • Download URL: eyconf-0.0.5.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for eyconf-0.0.5.tar.gz
Algorithm Hash digest
SHA256 efd6e89baaf7211629d9342012c98dc24fa72a2dbe0e84cb508df2bc5a5eca84
MD5 e57eb55a6a6e4dda6701645bffbe70a1
BLAKE2b-256 2c400b9a33b8f379ae5d647db76f8ccbbe563a9c4be645f4a99ba30ea978ed76

See more details on using hashes here.

Provenance

The following attestation bundles were made for eyconf-0.0.5.tar.gz:

Publisher: publish.yml on semohr/eyconf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file eyconf-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: eyconf-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for eyconf-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e942af7f68ec0e3e75fe3a7781428dcb0e421fbcdb73f3937f671fa3deb92c61
MD5 7165d6230d80cef23d726d6b63d01ccc
BLAKE2b-256 9d7beb2dbac71e71f81705e4b0fe6e96bac5dde5857be4c17a19c28ce2a10c5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for eyconf-0.0.5-py3-none-any.whl:

Publisher: publish.yml on semohr/eyconf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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