Skip to main content

Simple configuration file loader

Project description

Smart-Config | 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 smart-config

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.3.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.3-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: smart_config-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 c3e260678330049051c8daf717df7311c4b281747746ea87c1de497f681e649b
MD5 67d74eb3fad86a64039f683751464be2
BLAKE2b-256 c82a752ea912883fc0c9323d34a91d101b30b3a1e02db90ffa7c4d0d73ffc11a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smart_config-0.1.3-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.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b9cec4f1fbc51602f1aae50277289d2d138e3280e0e493710fbd064325ba7761
MD5 3cd065850b3f44cf5c50ac07d5f9ce17
BLAKE2b-256 2f8169c0258c767cdaadf30e5d2d8457a83854ba58abb387536fefb443d07aa2

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