magnet
A library that makes it easy to load YAML config files in a hierarchical
manner. Also loads YAML content from CONFIG environment variable.
Minimal Python version is Python 3.5.
Installation
pip install magnet
Usage
Consider the following yaml file config/default.yml:
app:
url: https://www.example.com/app
certs:
pem: /path/to/cert.pem
key: /path/to/cert.key
clients:
- a
- b
And the following config/local.yml file:
app:
url: https://app.example.com/
from magnet import Config
config = Config().read_all()
config['app.url'] # ==> "https://app.example.com"
config['app.certs.pem'] # ==> "/path/to/cert.pem"
config['non.existing.key'] # ==> raises KeyError
Additional options:
from magnet import Config
# Listed below are the default parameters
config = Config(
config={
# set default configuration here
},
filenames=(
'config/default.yml',
'config/local.yml',
),
env_variable='CONFIG',
separator='.',
)
config.read_all(
filename=None, # string, can be set to load an additional file
)
This will load the configuration in the following order:
./config/default.yml- can be committed to the repository./config/local.yml- should not be committed to allow custom config for devs- An additional YAML config file (if
filenameargument is defined) - YAML contents from the
CONFIGenvironment variable (ifenv_variableis defined)
All of these files are optional, but the key lookups will result with
KeyError if a key is missing. If filename is defined, but the file is not
found, it will raise a FileNotFoundError.
Development
make ci - Run the CI pipeline (deps, lint, test-coverage)
make lint - Lint all project files
make test - Run all tests
make test-watch - Run all tests and re-run on file changes
make test-coverage - Run all tests and calculate test coverage
make deps - Create a virtual environment and install dependencies
make freeze - Freeze the requirements
make env - Create a virtual environment
Metadata
Release files for magnet 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| magnet-1.1.1.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| magnet-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.9 kB
Release files / magnet-1.1.1.tar.gz
| Download URL | magnet-1.1.1.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
018ef8324b5c228a6a62c163f0f720e97c2d8c65e4a72721074900c715c4e0c7
|
|
BLAKE2b-256 checksum How to use checksums |
af711414849fb235df70d88ef998a11476b410c642988f2c5ddbdb5ca7832108
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / magnet-1.1.1-py3-none-any.whl
| Download URL | magnet-1.1.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
089d198391bd415224d30677354116195a6193dcfaf902b6b141ab994e77fede
|
|
BLAKE2b-256 checksum How to use checksums |
84cec0680770c4ff7c5db7b5e2388571d720c76616c860b09a41e0b02b2a89fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |