Skip to main content

Here is a full working example of using easy_config. First, write your configuration class:

# config.py
from easy_config import EasyConfig

class MyProgramConfig(EasyConfig):
   FILES = ['myprogram.ini']
   NAME = 'MyProgram'  # the name for the .ini file section and the namespace prefix for environment variables

   # define the options like you would a dataclass
   number: int
   name: str
   check_bounds: bool = True  # options with defaults must all come after non-default options

A sample configuration file:

# myprogram.ini
[MyProgram]
# section name matches `NAME` from the configuration class
number = 3

And a sample program to illustrate the usage:

# test_config.py
import sys

from config import MyProgramConfig

print(MyProgramConfig.load(name=sys.argv[1])

Running this program with various options:

$ python test_config.py Scott
MyProgramConfig(number=3, name='Scott', check_bounds=True)

$ env MYPROGRAM_CHECK_BOUNDS=False python test_config.py Scott
# environment variable names are the all-uppercase transformation of the NAME concatenated with the option name and an underscore
MyProgramConfig(number=3, name='Scott', check_bounds=False)

$ env MYPROGRAM_NUMBER=10 MYPROGRAM_NAME=Charlie python test_config.py Scott
MyProgramConfig(number=10, name='Scott', check_bounds=True)

As you can see, values are taken in precedence, with arguments passed to load overriding values from the environment which, in turn, override values from configuration files.

Once you have the MyProgramConfig instance, you can use it just like any dataclass.

Metadata

Release files for easy-config 0.2.0

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

Source distribution (sdist)

Source distribution for easy-config 0.2.0
File Size Uploaded Provenance
easy_config-0.2.0.tar.gz 11.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for easy-config 0.2.0
File Interpreter ABI Platform
easy_config-0.2.0-py36-none-any.whl Python 3.6 none any Details

Total release size: 18.3 kB

Release files / easy_config-0.2.0.tar.gz

Download URL easy_config-0.2.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8de3469b925c5c7f9426902520903f600466d0b648c373f82fce219730f3282b
BLAKE2b-256 checksum
How to use checksums
9da1254f36f7876b8d41bf9493ff3a8a68befa51fdebb4b6862daa4135079845
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Release files / easy_config-0.2.0-py36-none-any.whl

Download URL easy_config-0.2.0-py36-none-any.whl
Size 7.2 kB
Tags Python 3.6
SHA-256 checksum
How to use checksums
6571155bce0c3875a0c410b994f16e03e65a7dcb866606d1df2531dfa93284d6
BLAKE2b-256 checksum
How to use checksums
be8a121dc8a5a5e805f68b988c14e1278211b75eb2b46f39b9447f309081f9cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Security for easy-config 0.2.0

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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