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

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: smart_config-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 4796ea7de631c50548119b2902d15dc167c3ca6fdf801656341200f0c3f50f7d
MD5 bb7e8a9316accb395d65af23756f1616
BLAKE2b-256 d4f8329a2ee4e5532a9a6cc87924b209eeadb239e37e91579dd291b8d8ff6ed2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smart_config-0.1.2-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.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a1009f5ef77ac6a62115af54902bf05ba8615a137c8d67219a2b9b0e516e00c0
MD5 e6f7f1fd815de1aa1bb87256341819ee
BLAKE2b-256 b3362a7bf1d4e44760de98ebb89abbb34cf55c041476a36eb38bab01cf844a63

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