donfig


Namedonfig JSON
Version 0.8.1 PyPI version JSON
download
home_page
SummaryPython package for configuring a python package
upload_time2023-07-15 03:07:18
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
keywords task-scheduling parallel numpy pandas pydata
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Donfig
======

.. image:: https://github.com/pytroll/donfig/workflows/CI/badge.svg?branch=main
    :target: https://github.com/pytroll/donfig/actions?query=workflow%3A%22CI%22

.. image:: https://codecov.io/gh/pytroll/donfig/branch/main/graph/badge.svg?token=xmvNtxzdoB
   :target: https://codecov.io/gh/pytroll/donfig

.. image:: https://anaconda.org/conda-forge/donfig/badges/version.svg
   :target: https://anaconda.org/conda-forge/donfig/

.. image:: https://results.pre-commit.ci/badge/github/pytroll/donfig/main.svg
   :target: https://results.pre-commit.ci/latest/github/pytroll/donfig/main
   :alt: 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 <https://donfig.readthedocs.io/en/latest/>`_.

Installation
------------

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/__init__.py
    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
    else:
        # something else

Set configuration in Python
---------------------------

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

.. code-block:: python

    # 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:

.. code-block:: python

    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:

.. code-block:: bash

    export MYPKG_MY_KEY="a value"

And can be accessed in python:

.. code-block:: 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

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "donfig",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "David Hoese <david.hoese@ssec.wisc.edu>",
    "keywords": "task-scheduling parallel numpy pandas pydata",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/00/3e/eb3e29a1720e8a2e2a7f4a6952b1e746af4135a46469209b1b49bfc043b5/donfig-0.8.1.tar.gz",
    "platform": null,
    "description": "Donfig\n======\n\n.. image:: https://github.com/pytroll/donfig/workflows/CI/badge.svg?branch=main\n    :target: https://github.com/pytroll/donfig/actions?query=workflow%3A%22CI%22\n\n.. image:: https://codecov.io/gh/pytroll/donfig/branch/main/graph/badge.svg?token=xmvNtxzdoB\n   :target: https://codecov.io/gh/pytroll/donfig\n\n.. image:: https://anaconda.org/conda-forge/donfig/badges/version.svg\n   :target: https://anaconda.org/conda-forge/donfig/\n\n.. image:: https://results.pre-commit.ci/badge/github/pytroll/donfig/main.svg\n   :target: https://results.pre-commit.ci/latest/github/pytroll/donfig/main\n   :alt: pre-commit.ci status\n\nDonfig is a python library meant to make configuration easier for other\npython packages. Donfig can be configured programmatically, by\nenvironment variables, or from YAML files in standard locations. The\nbelow examples show the basics of using donfig. For more details see the\nofficial `documentation <https://donfig.readthedocs.io/en/latest/>`_.\n\nInstallation\n------------\n\nDonfig can be installed from PyPI using pip:\n\n.. code-block:: bash\n\n    pip install donfig\n\nOr with conda using the conda-forge channel:\n\n.. code-block:: bash\n\n    conda install -c conda-forge donfig\n\nUsing Donfig\n------------\n\nCreate the package-wide configuration object for your package named `mypkg`:\n\n.. code-block:: python\n\n    # mypkg/__init__.py\n    from donfig import Config\n    config = Config('mypkg')\n\nUse the configuration object:\n\n.. code-block:: python\n\n    from mypkg import config\n    important_val = config.get('important_key')\n    if important_val:\n        # do something\n    else:\n        # something else\n\nSet configuration in Python\n---------------------------\n\nConfiguration can be modified in python before code using it is called:\n\n.. code-block:: python\n\n    # mypkg/work.py\n    from mypkg import config\n    config.set(important_key=5)\n\n    # use the configuration\n\nDonfig configurations can also be changed as a context manager:\n\n.. code-block:: python\n\n    config.set(other_key=True)\n\n    with config.set(other_key=False):\n        print(config.get('other_key'))  # False\n\n    print(config.get('other_key'))  # True\n\nConfigure from environment variables\n------------------------------------\n\nEnvironment variables are automatically loaded when the Config object is\ncreated. Any environment variable starting with the name of the config\nobject in all capital letters and an underscore will be loaded in to\nthe config object:\n\n.. code-block:: bash\n\n    export MYPKG_MY_KEY=\"a value\"\n\nAnd can be accessed in python:\n\n.. code-block:: python\n\n    from mypkg import config\n    print(config.get('my_key'))\n\nConfigure from YAML file\n------------------------\n\nDonfig will also automatically load any YAML configuration files found in\nspecific paths. The default paths:\n\n- ~/.config/<config name>/\n- /etc/<config name>/\n- <sys.prefix>/etc/<config name>/\n\nNote the `/etc/<config name>/` directory can also be specified with the\nenvironment variable `DASK_ROOT_CONFIG`. Also note that\n`~/.config/<package name>` (or other location specified with `DASK_CONFIG`)\ncan be created as a custom user configuration file for easier user\ncustomization (see documentation for details).\n\nHistory\n-------\n\nDonfig is based on the original configuration logic of the `dask` library.\nThe code has been modified to use a config object instead of a global\nconfiguration dictionary. This makes the configuration logic of dask available\nto everyone. The name \"donfig\" is a shortening of \"dask.config\", the original\ndask module that implemented this functionality.\n\nLicense\n-------\n\nOriginal code from the dask library was distributed under the license\nspecified in `DASK_LICENSE.txt`. In November 2018 this code was migrated to\nthe Donfig project under the MIT license described in `LICENSE.txt`. The full\ncopyright for this project is therefore::\n\n    Copyright (c) 2018 Donfig Developers\n    Copyright (c) 2014-2018, Anaconda, Inc. and contributors\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python package for configuring a python package",
    "version": "0.8.1",
    "project_urls": {
        "Homepage": "https://github.com/pytroll/donfig"
    },
    "split_keywords": [
        "task-scheduling",
        "parallel",
        "numpy",
        "pandas",
        "pydata"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "003eeb3e29a1720e8a2e2a7f4a6952b1e746af4135a46469209b1b49bfc043b5",
                "md5": "ecf123591d3900fcd959f2f12c8caaaa",
                "sha256": "d1773b550e5f1e0930dee03565ce610d1c53a9f9af95fcc46f587cc70e9d39ff"
            },
            "downloads": -1,
            "filename": "donfig-0.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ecf123591d3900fcd959f2f12c8caaaa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 21581,
            "upload_time": "2023-07-15T03:07:18",
            "upload_time_iso_8601": "2023-07-15T03:07:18.318352Z",
            "url": "https://files.pythonhosted.org/packages/00/3e/eb3e29a1720e8a2e2a7f4a6952b1e746af4135a46469209b1b49bfc043b5/donfig-0.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-15 03:07:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pytroll",
    "github_project": "donfig",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "donfig"
}
        
Elapsed time: 0.09019s