Skip to main content

Dad for your config

Project description

ABConfig

Install

pip install abconfig

Example:

from abconfig import ABConfig

class DBConf(ABConfig):
	path 
    redis = '127.0.0.1:6379'
    postgres = dict(
		user='db_user',
        password='db_password'
        host='localhost',
        port='5432',
    )

This class will be read file:

Json
{ 
    "redis": "172.17.0.1:6379",
    "postgres": {
		"user": "db_user",
        "password": "db_password",
        "host": "172.17.0.1",
        "port": "5432"
    }
}

or

Yaml
redis: "172.17.0.1:6379"
postgres:
  user: "db_user"
  password: "db_password"
  host: "172.17.0.1"
  port: "5432"

Create instance and use .get() or .get(key, default)

>> conf = DBConf()
>> conf.get()
{'redis': '172.17.0.1:6379', 'postgres': {'user': 'db_user', 'password': 'db_password', 'host': '172.17.0.1', 'port': '5432'}}
>> conf.get('redis')
172.17.0.1:6379
>> conf['postgres']['user']
db_user

To override value with environment variables, add them to os env in uppercase:

REDIS="172.17.0.3:6379"
POSTGRES_HOST="172.17.0.3"
POSTGRES_PORT="5432"

and create new class instance

>> conf = DBConf()
>> conf.get()
{'redis': '172.17.0.3:6379', 'postgres': {'user': 'db_user', 'password': 'db_password', 'host': '172.17.0.3', 'port': '5432'}}

Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
abconfig-0.4.0-py3-none-any.whl (5.1 kB) Copy SHA256 hash SHA256 Wheel py3
abconfig-0.4.0.tar.gz (3.7 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page