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"

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.3.tar.gz (30.5 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.3-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: eyconf-0.0.3.tar.gz
  • Upload date:
  • Size: 30.5 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.3.tar.gz
Algorithm Hash digest
SHA256 d59a22647ba40a633d3325b94f9bcf4e086b6944c191945479ae5071178479bc
MD5 9985f4df645c26cbccb85b92f03d6a8e
BLAKE2b-256 393884df49974fdcb1dd05f4ca10822fbc2af46dab94aa2b8af910c30172f0b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for eyconf-0.0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: eyconf-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 22.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e2154bc4265347c8bbeb5ca57e165d1a8b959a7b2bf0e94d4460b5fa4a19954c
MD5 575fd83a394a72f452508c73cc0137f3
BLAKE2b-256 f80c9bcb78daf56215bae39717b9f9c87b766c520c6791732a4268e78a8025e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for eyconf-0.0.3-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