Skip to main content

config-proxy

This is a Python module that enables you to setup paths for both json configuration and configuration from env variables.

It automatically looks into environmental variables and either uses its value, or looks it up in json configuration file or falls back to default.

Install

Either clone from this repository or use pip / poetry like so:

Via pip

pip install config-proxy

Using poetry

poetry add config-proxy

Usage

Basic usage

If your configuration file is either called config.json and is expected in the current working directory or its location is set using CONFIG_PATH environmental variable, the usage is fairly easy:

config.json

{
  "database": {
    "host": "mydbhost.databases.com"
  }
}

main.py

from config_proxy import StringProperty

database_host = StringProperty(path="database.host", env="DATABASE_HOST", default="localhost")

print(database_host.value)
$ python main.py
mydbhost.databases.com

$ DATABASE_HOST="overridden.database.com" python main.py
overridden.database.com

Advanced usage

If you want to specify configuration file path and customize env variable that stores the path, you have to extend the ConfigProxy class and overload attributes you wish to change.

my-special-config.json

{
    "database": {
        "host": "mydbhost.databases.com"
    }
}

custom.py

from config_proxy import ConfigProxy as _ConfigProxy, StringProperty

class ConfigProxy(_ConfigProxy):
    env_location = "ENV_VARIABLE_THAT_CONTAINS_MY_CONFIG_PATH"
    config_file_names = ["my-special-config.json"]

Please note, that StringProperty now does not know it should use your subclass instead, do not forget to specify it when creating the property:

database_host = StringProperty(path="database.host", env="DATABASE_HOST", default="localhost", proxy=ConfigProxy)

print(database_host.value)

If you want to specify a custom config file, you can use:

$ ENV_VARIABLE_THAT_CONTAINS_MY_CONFIG_PATH="/actual/path/to/my/config.json" python custom.py
mydbhost.databases.com

Metadata

Release files for config-proxy 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for config-proxy 0.1.5
File Size Uploaded
config-proxy-0.1.5.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for config-proxy 0.1.5
File Interpreter ABI Platform
config_proxy-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / config-proxy-0.1.5.tar.gz

Download URL config-proxy-0.1.5.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2cd19f88fa25c4674dbf12dc5902089b026fda2d4a3f007f6d4c552319e1fb1f
BLAKE2b-256 checksum
How to use checksums
b2d03456faa06e5fb22126a0352ab0c1abaff39237767fe10de1db7f1e2794f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.1 Linux/5.9.12

Release files / config_proxy-0.1.5-py3-none-any.whl

Download URL config_proxy-0.1.5-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aba9cb46083ce7825b35ecffd9da5d5e7c2946cc985d874a520ed84909930b3b
BLAKE2b-256 checksum
How to use checksums
a1efed80d626f9c177de5273285931b04b2986382bbb915ebe04c0cecc7ad043
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.1 Linux/5.9.12

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page