simple Python config in your home directory
Project description
cnfg
Simple configuration should be simple. Here’s example.py:
import cnfg settings = cnfg.load('.examplerc') print(settings['message'])
Relative paths are awful. Not all systems have /etc. The only reasonable place to put configuration is in your home directory.
JSON and YAML are not Python. eval is not so bad. Here’s .examplerc:
# It's Python, so you can use comments (and more) {"message": "My custom message."}
Now all of these work, with relative directories as implied:
./example.py python ../example.py cat example/example.py | python
What about default settings?
It’s up to you, but it’s easy, especially if you’re keeping all your configuration in a dict:
settings = {"message": "Default message!"} settings.update(cnfg.load('.examplerc'))
What about environment variables?
It’s up to you, but it’s easy:
import os some_var = os.getenv("SOME_VAR", "some default value")
What about “from config import settings,” like confire?
It’s up to you, but it’s easy. Just make a file called config.py and define settings in it.
Where’s my home directory?
On a Mac or Linux machine, echo ~. On Windows, echo %userprofile%.
This is so abstract!
Check out the example.
This is so trivial!
Yes, it’s as simple as possible, and it’s useful all over the place and the right level of complexity for a lot of projects.
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
File details
Details for the file cnfg-1.0.0.tar.gz
.
File metadata
- Download URL: cnfg-1.0.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f43ea123d149c6e38a301d55d95ae4821725aaab283ff27d71817675a944381 |
|
MD5 | b3dc6b1bcd9e64a58db0ef9b4d963e81 |
|
BLAKE2b-256 | 0cc24cc9aa8c46660453279fd0f8576e490f0787d28e145de63367a3ce77fe16 |