Skip to main content

Boîte à outils Python made in Lincoln

Project description

lincolntools-config

lincolntools : Python toolbox made in Lincoln France

  • Author: Lincoln Innovation
  • Creation date: 2020-10-01
  • see AUTHORS.md

This package belongs to the lincolntools namespace
The goal of this package is to provide the necessary tools to create a unique and global configuration object that can be queried anywhere in a Python project.

Table of content

  1. Documentation
  2. Tests
  3. Contribute
  4. History
  5. Credits

Installation

    pip install lincolntools-config

How to use

There are several possibilities to load a YAML configuration file :

  • Provide the path to a file which will be processed and transformed into a Python dict
  • Provide the path to a folder that contains one or more YAML files that will be concatenated into a single object.

Example

In the following examples we suppose our config folder has the given structure :

└── config
    ├── config_foo
        ├── foo.yaml               
        └── foo.template 
    └── config_bar
        ├── bar.yaml               
        └── bar.template 

foo.yaml

foo:
    foo_key : foo_value

bar.yaml

bar:
    bar_key : bar_value

Code :

from lincolntools.config import Config
my_config = Config('/path/to/config')
print(my_config.conf)
# {'foo': {'foo_key': 'foo_value'}, 'bar': {'bar_key': 'bar_value'}, '_version': 1}
print(my_config.get('foo'))
# {'foo_key': 'foo_value'}

print(my_config.get('foo').get('foo_key'))
# foo_value

print(my_config.get('foo')['foo_key']) # same as above but with another syntax
# foo_value

print(my_config.flatten())
# {'foo-foo_key': 'foo_value', 'bar-bar_key': 'bar_value'}

print(my_config.dump())
# _version: 2
# bar:
#   bar_key: bar_value
# foo:
#   foo_key: foo_value

Important

The Config class is based on the Single design pattern (official documentation).
TLDR : Only one instance of Config can be initialized during the whole program lifetime.

from lincolntools.config import Config
my_first_config = Config('/path/to/config') # ok, no other instance exists
my_other_config = Config('/path/to/config') # nok
# Exception: This is a singleton

Tests

Launch tests with the default Python version :

# in the project folder
pytest

Launch tests on multiple Python versions (see tox.ini) :

# in the project folder
tox

History

Voir HISTORY.md

Credits

This package was inspired by Cookiecutter_ and the audreyr/cookiecutter-pypackage_ project template.

History

1.0.0 (2020-10-01)

  • First version

1.0.1 (2021-01-15)

  • Adding cfg_path argument in get/get_instance methods
  • Adding easydict for more convenient navigation

1.0.2 (2021-01-15)

  • Now look for .yaml and .yml files when directory is provided

1.0.3 (2021-02-05)

  • Concatenante yaml files before parsing. Allows anchor to be cross files.

1.0.4 (2021-08-10)

  • Documentation and comments translation.

Project details


Download files

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

Source Distribution

lincolntools-config-1.0.5.tar.gz (22.4 kB view details)

Uploaded Source

File details

Details for the file lincolntools-config-1.0.5.tar.gz.

File metadata

  • Download URL: lincolntools-config-1.0.5.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.5

File hashes

Hashes for lincolntools-config-1.0.5.tar.gz
Algorithm Hash digest
SHA256 8d36e54779e7a1d551e75486df55eb4a1a873b83f3fc66b5535b365bb1bf2722
MD5 c92c65b37ae08953d62291299607e0fd
BLAKE2b-256 326bfcfdd9ff22f9c7b495173be6713ba04bd221cb32798b7fa98a2889145b21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page