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.4.tar.gz (31.0 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.4-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: eyconf-0.0.4.tar.gz
  • Upload date:
  • Size: 31.0 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.4.tar.gz
Algorithm Hash digest
SHA256 9ef264670cd448c1e32ae91bca056c01dc867e37efeca7cdc79cd03a67b7751b
MD5 2e0f585437bdb951ddb8c33c02692711
BLAKE2b-256 f4a1c6c76b92253a51cfa902aa76b86425455b9cb985c3778588b07f732c5f1d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: eyconf-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 22.5 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c18843e4d87ac6f51889f08ec92c4cc08947e6266146d52824d3e40ac7fd98d0
MD5 c181d6cf85e4ef5527c124dedebe65e8
BLAKE2b-256 02ebf8c96a806e06b498c7277bef71166960af66f7e83086cfcc6517360c01f3

See more details on using hashes here.

Provenance

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