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
The following are the default locations that will be searched
~/.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
# My config.toml 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 pi-conf module.
# __init__.py
from pi_conf import load_config
cfg = load_config("ourappname") ## Loads the config from the application <appname> directory
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 load_config ## Just load it again
cfg = load_config("ourappname")
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
pi_conf-0.8.5.2.tar.gz
(13.4 kB
view details)
Built Distribution
pi_conf-0.8.5.2-py3-none-any.whl
(15.7 kB
view details)
File details
Details for the file pi_conf-0.8.5.2.tar.gz
.
File metadata
- Download URL: pi_conf-0.8.5.2.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.9 Darwin/23.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f61ebf0e5c64d6a16c56fc355ae7d1983e4270009488b7180abd1c31767da5f |
|
MD5 | abc0fc3edf6b394ec8be96cbf39fa11d |
|
BLAKE2b-256 | e5d3368e4fa22c04c0aca170b7d1373d394a7b1002dbf3b7a3fca501307c2e04 |
File details
Details for the file pi_conf-0.8.5.2-py3-none-any.whl
.
File metadata
- Download URL: pi_conf-0.8.5.2-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.9 Darwin/23.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fc13dbeafceac7250fa347d04e299d8d9cc3f4fc7cb1b73da2b69f7a63150ec |
|
MD5 | b906843c462da35a1096fc3106fa2fc6 |
|
BLAKE2b-256 | b02c593240774ab8a78993afa1b3763d062af3e33c758bcb0801b5dbbb2a530f |