Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

user_config

Manage user configuration for python projects.

For easy and well-documented user-defined configuration.

Badges

Fallback order

  1. command line arguments

  2. user config files in ~/.config/<app>/config.<extension>

  3. global config files in /etc/xdg/<app>/config.<extension>

  4. default values

For directories on operating systems than linux, see: https://github.com/ActiveState/appdirs

Config format

Supported out of the box: ini

Other config formats can be supported via plug-ins.

Requirements

  • Linux, or Os X, or Windows (but not Windows Vista)

  • python 2.7 or newer (python 3.6 supported)

  • relatively new versions of setuptools and pip (version requirement to follow)

Examples

Simple configuration example

"""Usage example for user_config."""
from user_config import Config, Section, StringOption, IntegerOption

class MyConfig(Config):

    """This will be displayed in the configuration documentation."""

    application = "my_application"
    author = "me"

    class GeneralSection(Section):
        """General information."""
        name = StringOption(
            doc="your name",
            default="unknown person")
        age = IntegerOption(
            doc="your age",
            required=True)
    general = GeneralSection()
    class AddressSection(Section):
        """shipping address"""
        street = StringOption(
            doc="street including house number",
            required=True)
        city = StringOption(required=True)
    address = AddressSection(required=False)

if __name__ == "__main__":
    CONFIG = MyConfig()
    print("hello there, {}!".format(CONFIG.general.name))

Command line help text:

$ python examples/simple_example.py -h
usage: my_application [-h] [--generate-config] [--city CITY] [--street STREET]
                      [--age AGE] [--name NAME]

This will be displayed in the configuration documentation. Command line
arguments overwrite configuration found in:
/root/.config/my_application/config.cfg /etc/xdg/my_application/config.cfg

optional arguments:
  -h, --help         show this help message and exit
  --generate-config  print a complete configuration file with current settings
  --city CITY
  --street STREET    street including house number
  --age AGE          your age
  --name NAME        your name

Command line use with default value:

$ python examples/simple_example.py --age 211
hello there, unknown person!

Command line use without required value:

$ python examples/simple_example.py
Traceback (most recent call last):
  File "examples/simple_example.py", line 29, in <module>
    CONFIG = MyConfig()
  File "/git/user_config/user_config/user_config/__init__.py", line 622, in __init__
    self._elements[element].validate_data(self._data)
  File "/git/user_config/user_config/user_config/__init__.py", line 464, in validate_data
    self._elements[element].validate_data(self._data)
  File "/git/user_config/user_config/user_config/__init__.py", line 380, in validate_data
    self.element_name))
user_config.MissingData: no value was provided for required option age

Command line use:

$ python examples/simple_example.py --age 211 --name mystery_user
hello there, mystery_user!

Generate configuration file:

$ python examples/simple_example.py --generate-config
## This will be displayed in the configuration documentation.

[general]
## General information.

## your name
# name = unknown person
name = tamara

## your age
## REQUIRED
# age =
age =


[address]
## shipping address
## OPTIONAL_SECTION

## street including house number
## REQUIRED
# street =
street =

## REQUIRED
# city =
city =

Documentation

$ pip install -e ".[doc]"
$ python setup.py build_sphinx

Testing

  • pytest

  • pytest-cov

  • coverage

  • codacy-coverage

$ python -m pytest --cov=user_config --cov-report xml

Planned features

  • multi matching sections / wildcard sections

  • yaml config format

  • json config format

  • hook for overwriting config from database or other storage function

Metadata

Release files for user-config 1.0a6.post37

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

Source distribution (sdist)

Source distribution for user-config 1.0a6.post37
File Size Uploaded Provenance
user_config-1.0a6.post37.tar.gz 1.1 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for user-config 1.0a6.post37
File Interpreter ABI Platform
user_config-1.0a6.post37-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 1.1 MB

Release files / user_config-1.0a6.post37.tar.gz

Download URL user_config-1.0a6.post37.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
1dd82f5af09ef131d3caf8fe76c0f66a4b9b7fe2ceb09f019635773739ebc208
BLAKE2b-256 checksum
How to use checksums
4c83aa33469cd010fb7152d43274513cc603613c396e4c925ce1c000f9e2afb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / user_config-1.0a6.post37-py2.py3-none-any.whl

Download URL user_config-1.0a6.post37-py2.py3-none-any.whl
Size 13.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ccbeb39d88a01e6fb14faa852d188fc508483c4d7c8d4b4a29e21dacedfab982
BLAKE2b-256 checksum
How to use checksums
ccf7d27c8de2edf171883c82c1e2e4ed5ac1a70dd7a1ef79c7ddcf9424ee40d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for user-config 1.0a6.post37

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.

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