Easy configs for python projects
Project description
P-Conf
Easy use Configs for python projects. Allows loading the config files in the application directory (os specific). Once set the config can be used as a singleton across the project or pass around.
Locations for the config file
~/.config/<appname>/config.(toml|json|ini|yaml)
<system config directory>/<appname>/config.(toml|json|ini|yaml)
Example code
The example code uses the following as the example configuration file
foo = 1
[bar]
a = 2
Using inside of a single script
from pi_conf import load_config
cfg = load_config("ourappname")
print(cfg.foo) # 1
print(cfg.bar.a) # 2
Using inside of applications
The following is the preferred way of using the p-config module. We set it once in our __init__.py
then use it whichever files need it. Since cfg
is a singleton setting it multiple times is unnecessary and will cause it to load from the file again.
# __init__.py
from pi_conf import load_config
load_config("ourappname") ## Sets the config from the application <appname> directory
from pi_conf import cfg as cfg ## Allows the cfg to be importable from our app
Using the config in files
Once it the config has been set you can use it from any file doing either of the following methods.
- Option 1
from ourappname import cfg ## Import cfg from what we set in __init__.py
print(cfg.foo) # 1
- Option 2
from pi_conf import cfg ## Import the cfg from p-config
print(cfg.foo) # 1
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pi_conf-0.6.1.tar.gz
.
File metadata
- Download URL: pi_conf-0.6.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93a68a770d88ea399d4198aa12c1875caf382e673ac082d128842f4e9d9acf80 |
|
MD5 | 917e95f650710fc394c007bb341168a2 |
|
BLAKE2b-256 | cd648ccf043c0f9dde2a431eb6ff3dc2658acf8c63d78b6889bd16634101c923 |
File details
Details for the file pi_conf-0.6.1-py3-none-any.whl
.
File metadata
- Download URL: pi_conf-0.6.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 436c5ecf939ad2a3eb3baef3fe957eda85bbc541e4f0e2213161e9eaded44785 |
|
MD5 | e8931b094763bf5c9633c1ad4372a8b0 |
|
BLAKE2b-256 | f5fb9dfeaf344162170be09d17b42c0ad61625c3516aabd294aaf8aa854fe2b4 |