Skip to main content

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 set_config
cfg = set_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 set_config
set_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


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.7.8.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pi_conf-0.7.8.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pi_conf-0.7.8.1.tar.gz.

File metadata

  • Download URL: pi_conf-0.7.8.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for pi_conf-0.7.8.1.tar.gz
Algorithm Hash digest
SHA256 b536eb11f1e8d598cc773de2cf6c3efe1fca4310b716bd36dcb1c4a80572b086
MD5 c1908e640a3ba258d0aef03d80b2e80d
BLAKE2b-256 c6a822b00fe2bf8971493089a8b2e645211f8efcebad67e0936d6a3a2107e699

See more details on using hashes here.

File details

Details for the file pi_conf-0.7.8.1-py3-none-any.whl.

File metadata

  • Download URL: pi_conf-0.7.8.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for pi_conf-0.7.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4560027e1f519b1e9e9378d2a69ffd6194e507f3fad821441d4625ada4b58d0
MD5 91e8f61f41219a040fba4cbf6ca1eb53
BLAKE2b-256 1009946b199c48619028fd8ae3ccdfba41fb924b90e71f0a21d394f78d073152

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