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 your schema to a yaml configuration file, including comments!
  • Validate: Validate your 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 git directly using pip:

pip install git+https://github.com/semohr/eyconf.git

Quickstart

Define a configuration schema

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.2.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.2-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: eyconf-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 4079c68e43f867bfbf3bcd13f291fb4a3414a8bf016537f3478b4e933fbb7445
MD5 a826a67b83ea510a07c537d97082f5f4
BLAKE2b-256 d464bb93bd52b95cb30ce51bcfb3355bc893d9e97398511a580213c05b76fd97

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: eyconf-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 22.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f283570c62fc076ac3fdc93db11778a087685fef716ad3e7e6d4e0427de6ed3f
MD5 976cbcb5ea5376d704dc6c8c0bc27b3a
BLAKE2b-256 67f9dd1d4a7d913ed228aab269dc552259761de0e679a436fc1ce15c516f1861

See more details on using hashes here.

Provenance

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