Skip to main content

Simple configuration file loader

Project description

ConfigLoader | Build Latest Version Versions License

Simple configuration file loader

Why

Modern configuration file is more and more complex, flexible and readable, but had no option to pass environment variables. This project aim to simplify usage of the configuration file and environment variables for production and development, with easy dictionary like access

Supported files: ini, yaml, json & cfg

Install

pip install conf_loader

Basic usage

Let's assume we had a project with this config file system.yaml

# system.yaml
database:
    host: ${DATABASE_HOST:localhost}
    port: ${DATABASE_PORT:27017}
    username: ${DATABASE_USER:user}
    password: ${DATABASE_PASSWORD:password}
    database: ${DATABASE}

and environment variables set to

DATABASE_HOST=mongodb://xxx.xxx.xxx.xxx
DATABASE_USER=mongo
DATABASE_PASSWORD=changeit
DATABASE=Demo

parse file with ConfigLoader

from smart_config import ConfigLoader

# read file system.yaml and parse config
env = ConfigLoader('system.yaml').get_config()

# access whole database section
print(env['database'])

# {
# 'database': 'test',
# 'host': 'mongodb://xxx.xxx.xxx.xxx',
# 'user': 'mongo'
# 'password': 'changeit',
# 'port': 27017,
# 'database': 'demo'
# }

# access database host value
print(env['database']['host'])

# >> mongodb://xxx.xxx.xxx.xxx

# access database port value returns default value as DEFAULT_PORT is not set in environment
print(env['database']['port'])

# >> 27017

License

MIT licensed. See the LICENSE file for more details.

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

smart_config-0.1.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smart_config-0.1.1-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file smart_config-0.1.1.tar.gz.

File metadata

  • Download URL: smart_config-0.1.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200712 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for smart_config-0.1.1.tar.gz
Algorithm Hash digest
SHA256 01c8a0a3841fb6e0e1929c464bdf219da518420a5ca1375fffcc008aee8e3614
MD5 c2669b4367f0050ef657a17d31bb0358
BLAKE2b-256 f805ed44b5cbab9acdcbbc39cfd6e636ef8fdeb4182d4873ef7479414b645cbe

See more details on using hashes here.

File details

Details for the file smart_config-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: smart_config-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200712 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for smart_config-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bb28f1b6f9f76d8258f000412b9b227234734ef7b8e876fa1055fb64e990d142
MD5 2307df696ba6bcc9fcaa794c599f34dd
BLAKE2b-256 6fdeeb720a7a013bbd8b5f8d7cbd3a7c0c359b1c64754328f64dd5d05a0d25f8

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