Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

Python package for configuring a python package

Project description


.. image::

.. image::

.. image::

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 <>`_.


Donfig can be installed from PyPI using pip:

.. code-block:: bash

pip install donfig

Or with conda using the conda-forge channel:

.. code-block:: bash

conda install -c conda-forge donfig

Using Donfig

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

.. code-block:: python

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

Use the configuration object:

.. code-block:: python

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

Set configuration in Python

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

.. code-block:: python

# mypkg/
from mypkg import config

# use the configuration

Donfig configurations can also be changed as a context manager:

.. code-block:: python


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:

.. code-block:: bash

export MYPKG_MY_KEY="a value"

And can be accessed in python:

.. code-block:: python

from mypkg import config

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).


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.


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:

.. code-block:: literal

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

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for donfig, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size donfig-0.1.0.tar.gz (29.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page