Skip to main content
https://github.com/pytroll/donfig/workflows/CI/badge.svg?branch=main https://codecov.io/gh/pytroll/donfig/branch/main/graph/badge.svg?token=xmvNtxzdoB https://anaconda.org/conda-forge/donfig/badges/version.svg pre-commit.ci status

Donfig is a python library meant to make configuration easier for other python packages. Donfig can be configured programmatically, by environment variables, or from YAML files in standard locations. The below examples show the basics of using donfig. For more details see the official documentation.

Installation

Donfig can be installed from PyPI using pip:

pip install donfig

Or with conda using the conda-forge channel:

conda install -c conda-forge donfig

Using Donfig

Create the package-wide configuration object for your package named mypkg:

# mypkg/__init__.py
from donfig import Config
config = Config('mypkg')

Use the configuration object:

from mypkg import config
important_val = config.get('important_key')
if important_val:
    # do something
else:
    # something else

Set configuration in Python

Configuration can be modified in python before code using it is called:

# mypkg/work.py
from mypkg import config
config.set(important_key=5)

# use the configuration

Donfig configurations can also be changed as a context manager:

config.set(other_key=True)

with config.set(other_key=False):
    print(config.get('other_key'))  # False

print(config.get('other_key'))  # True

Configure from environment variables

Environment variables are automatically loaded when the Config object is created. Any environment variable starting with the name of the config object in all capital letters and an underscore will be loaded in to the config object:

export MYPKG_MY_KEY="a value"

And can be accessed in python:

from mypkg import config
print(config.get('my_key'))

Configure from YAML file

Donfig will also automatically load any YAML configuration files found in specific paths. The default paths:

  • ~/.config/<config name>/

  • /etc/<config name>/

  • <sys.prefix>/etc/<config name>/

Note the /etc/<config name>/ directory can also be specified with the environment variable DASK_ROOT_CONFIG. Also note that ~/.config/<package name> (or other location specified with DASK_CONFIG) can be created as a custom user configuration file for easier user customization (see documentation for details).

History

Donfig is based on the original configuration logic of the dask library. The code has been modified to use a config object instead of a global configuration dictionary. This makes the configuration logic of dask available to everyone. The name “donfig” is a shortening of “dask.config”, the original dask module that implemented this functionality.

License

Original code from the dask library was distributed under the license specified in DASK_LICENSE.txt. In November 2018 this code was migrated to the Donfig project under the MIT license described in LICENSE.txt. The full copyright for this project is therefore:

Copyright (c) 2018 Donfig Developers
Copyright (c) 2014-2018, Anaconda, Inc. and contributors

Release files for donfig 0.8.1.post1

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

Source distribution (sdist)

Source distribution for donfig 0.8.1.post1
File Size Uploaded
donfig-0.8.1.post1.tar.gz 19.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for donfig 0.8.1.post1
File Interpreter ABI Platform
donfig-0.8.1.post1-py3-none-any.whl Python 3 none any Details

Total release size: 41.1 kB

Release files / donfig-0.8.1.post1.tar.gz

Download URL donfig-0.8.1.post1.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3bef3413a4c1c601b585e8d297256d0c1470ea012afa6e8461dc28bfb7c23f52
BLAKE2b-256 checksum
How to use checksums
257180cc718ff6d7abfbabacb1f57aaa42e9c1552bfdd01e64ddd704e4a03638
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / donfig-0.8.1.post1-py3-none-any.whl

Download URL donfig-0.8.1.post1-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a3175ce74a06109ff9307d90a230f81215cbac9a751f4d1c6194644b8204f9d
BLAKE2b-256 checksum
How to use checksums
0cd5c5db1ea3394c6e1732fb3286b3bd878b59507a8f77d32a2cebda7d7b7cd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.8.1.post1 This release

2 release files

0.8.1

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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