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

Uploaded Source

Built Distribution

pi_conf-0.7.7.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pi_conf-0.7.7.2.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Darwin/23.0.0

File hashes

Hashes for pi_conf-0.7.7.2.tar.gz
Algorithm Hash digest
SHA256 7f86a634b5d5eaaf8ac1c2b869de403126089fc96e9327d4e5f392c6f952c672
MD5 53132747e3c6a3a24aacabbc1f7ebcb8
BLAKE2b-256 994191840bea0729f37025abd0aecf442a27393a55d9f6095b708bf56b77785e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pi_conf-0.7.7.2-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Darwin/23.0.0

File hashes

Hashes for pi_conf-0.7.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c925b298e21d114f4ad93e49b6937e0e1504ed19cbd6c12002e896e8fbc7acc9
MD5 f5a46e491ba5b514413eeec6e44377fc
BLAKE2b-256 2d992aa811f0098f8b256c2aed989748a3a210125aa0b1fddee7d4f9b5d3374e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page