When projects start to grow, the need for a globally accessible configuration manager is obvious.
Having configurations mapped to dictionaries is really useful, but can create a problem with memory.
Guachi not only holds persistent dictionaries on disk, but it also maps INI style keys to dictioanry keys, and can fill in the default values if some of them are missing.
You do not need to know anything about how guachi stores the values, just treat it like a regular dictionary!
User Interaction
Let’s assume you are dealing with a Twitter application that uses a ini file. This is a sampla INI file and how it looks:
[DEFAULT] app.twitter.username = alfredodeza app.update.frequency = 60 app.load.startup = False
We have a username, a frequency and a different setting for the startup option.
Lets deal with that:
ini_file = ``/Users/alfredo/.twwiter.ini`` conf = ConfigMapper(config_db_path) conf.set_config(ini_file)
That’s it! At this point, guachi has parsed the config file and stored the values.
Lets query them calling our keys:
>>> db_conf = conf.stored_config() >>> db_conf['frequency'] 60
Great, we now are making sure we have our data. We can actually get that value from anywhere in our twitter app by calling it this way:
db = ConfigMapper(config_db_path) conf = db.stored_config() frequency = conf['frequency']
Getting Deafults
Above we inspected an INI file with some changed values. But what happens when the user has none?
Since we set our defaults, we can be sure they are right there in case our app needs it in some sub-module:
>>> db = ConfigMapper(config_db_path) >>> conf = db.stored_config() >>> conf['load'] True
Updating Values
What if a user makes changes? We can always save and update what we read from the INI file at load time, to make sure we have the latest changes from the user:
conf = ConfigMapper(config_db_path) conf.update_config(ini_file)
Documentation
Our full Documentation is hosted here. Go take a look for the full API.
Metadata
Release files for guachi 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| guachi-0.0.6.tar.gz | 18.0 kB | Without provenance | Details for guachi-0.0.6.tar.gz |
Release files / guachi-0.0.6.tar.gz
| Download URL | guachi-0.0.6.tar.gz |
|---|---|
| Size | 18.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a77cbb09417bd09f2d989fedbc0a0a759f8aee1cb1731a89a816218f44e0e4fb
|
|
BLAKE2b-256 checksum How to use checksums |
fc1bff14ec04338cbf5558e1bd1f639ece257f69e6ef08a758c9072026f49852
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for guachi 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.