Skip to main content

A tool to handle configuration

Project description

ConfLoad

A tool to handle configurations

Support

format:

  • ini
  • json
  • yaml

origins:

  • url
  • environment
  • objects
  • files

Installation

.. code:: bash

pip3 install confload

Use

.. code:: python

from confload import Config

# Construct config with default values
cfg = Config({"test": 43})

# load from yaml, json or ini specificly
cfg.load_yaml("test.yml")

# guess loading type from suffix
cfg.load("test.ini")

cfg["abcd"]["test4"]["test2"] = 4  # automaticly create dict if key does not exists

dict(cfg)  # convertible to dict, best is to use dict method
cfg.dict(copy=False)

# update methods are currently merge and replace
cfg["abcd"].merge(test4={"test3": 5})  # Merge recursively merge two dicts objects
cfg["abcd"].replace(test4={"test3": 5})  # replace will replace objects as dict's update builtins method
cfg["abcd"].update(test4={"test3": 5})  # use the strategy defined on cfg build

# You can also load your config from an url (method's parameters are passed to requests.get method)
cfg.request_json("my_site.com/config.json")

# Or from your env
cfg.env_json("MY_JSON_FILE")  # Precise the format
cfg.env("MY_INI_FILE")  # or let it guess using the file suffix

cfg.dump_json("myfile.json")  # can be yaml but not ini file

Nb: most of the methods can be chained

.. code:: python

cfg = Config(...).update(...).env(...).load(...)

Futur

  • add support for argparse
  • add support for environment variables that are not files (e.g.: MY_CUSTOM_PORT=80)
  • documentation will be done, some change may appear as well.

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

confload-0.1.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

confload-0.1-py3-none-any.whl (16.5 kB view hashes)

Uploaded Python 3

Supported by

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