cfgsaver
Python library to save and fetch configuration data in a standard/conventional path and format.
Installation
pip install cfgsaver
Usage
Import the cfgsaver module to save/read configuration values in your source files:
from cfgsaver import cfgsaver
def save_config():
# saves configuration data to ~/.config/<your_package>/cfg.json
# unless cfgpath parameter is overridden:
config = {'name': 'Prahlad',
'language': 'Python',
'framework': 'Flask'
}
cfgsaver.save('<your_package>', config)
def get_config():
# gets configuration data from ~/.config/<your_package>/cfg.json
# unless cfgpath parameter is overridden:
config = cfgsaver.get("<your_package>") #returns None if config file doesn't exist
In case you want to ship some default configuration data packaged with your app, then read the below instructions carefully:
Ensure to include the path to your cfg.json in MANIFEST.in as follows (you'll have to copy this file from ~/.config/<your_package> to your source directory for packaging purpose):
include <your_package>/cfg.json
Override the PostInstall class in your setup.py like this in order to save your config file to the user's machine after installation:
from setuptools import setup, find_packages
from setuptools.command.install import install
import shutil
class PostInstallCommand(install):
"""Post-installation for installation mode."""
def run(self):
install.run(self)
fpath = os.path.join(self.install_lib, your_package)
fpath = os.path.join(fpath, "cfg.json")
tpath = os.path.join(os.path.expanduser("~"), ".config/<your_package>/cfg.json")
if not os.path.isdir(tpath):
os.makedirs(tpath)
shutil.move(fpath, tpath)
s = setup(
name = "your_package",
packages=find_packages(),
..
..
..
cmdclass={
'install': PostInstallCommand,
},
)
Attribution
Metadata
Release files for cfgsaver 1.0.4
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 |
|---|---|---|---|---|
| cfgsaver-1.0.4.tar.gz | 3.8 kB | Without provenance | Details for cfgsaver-1.0.4.tar.gz |
Release files / cfgsaver-1.0.4.tar.gz
| Download URL | cfgsaver-1.0.4.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d12de211624be818e4596a08cd2d448098e9e8bf9500bb9f974b17f9267c4c48
|
|
BLAKE2b-256 checksum How to use checksums |
6761daf64653e81eee5aa282b937b3f83e22b5845eef2ca77546f4ec0128e34c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6
|
Security for cfgsaver 1.0.4
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.