Automatic Python Environment Variable Configuration
Project description
PyConfig
Automatic Python Environment Variable Configuration Package
Description
PyConfig is a DevOps tool that helps Python developers to efficiently import various configuration files into their environment. It also automates config file exports to VCS such as Git while hiding sensitive information.
Installation
Install PyConfig with Pip:
pip install pyconfig-env
Upgrade using the -U flag:
pip install -U pyconfig-env
Usage
Importing into the environment
After installing, import PyConfig into your main Python file:
import pyconfig
Then you can import configurations as Python files, JSON objects, JSON files, or .env files:
# Python file
pyconfig.parse_py('config.py')
# JSON object
json_dict = {'DEBUG': True}
pyconfig.parse_json_obj(json_dict)
# JSON file
pyconfig.parse_json('config.json')
# .env file
pyconfig.parse_env('config.env')
The variables can be accessed anywhere in the Python program via os.environ:
print(os.environ['DEBUG']) # Prints True
Exporting a file for VCS
PyConfig currently only supports exporting Python config files for VCS. In order to make use of this feature, first ensure that the original config file is hidden from the VCS. For example, with Git, add the filename to a .gitignore file.
# config.py - This file was added to .gitignore
DEBUG = True # Ending a line with an asterisk (*) denotes a variable that is safe to upload in the VCS system*
SECRET = 'database password' # All other variables will be cleared for the template configuration file (config.py.sample)
Then simply generate the template configuration file:
pyconfig.py_template('config.py') # Creates config.py.sample
# config.py.sample
DEBUG = True # Ending a line with an asterisk (*) denotes a variable that is safe to upload in the VCS system
SECRET = '' # All other variables will be cleared for the template configuration file (config.py.sample)
As shown above, the entire file remained exactly the same, except that the variables which were not marked as safe had their values cleared. The asterisks at the end of the lines were also removed, as they are unnecessary for the VCS system itself.
Developers
Ashish D'Souza - @computer-geek64
Releases
The current stable release for PyConfig is v1.0.0
It is also released as a Python package on PyPI (the Python Package Index).
Versioning
This project is uses the Git Version Control System (VCS).
License
This project is licensed under the MIT License.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyconfig-env-1.0.0.tar.gz.
File metadata
- Download URL: pyconfig-env-1.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
926430bce2c25608bb920e4efb230e50d08f787ae0a8ec005e0d61b83e9a46e9
|
|
| MD5 |
0576de5f943794d6861c6f97be98019b
|
|
| BLAKE2b-256 |
46f5a37fe77f8c34e894c82f3654e9d880039bfaaa5dfc307ce402a112b3169c
|
File details
Details for the file pyconfig_env-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyconfig_env-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a58d31f9959e8100e3014993241180316a260e4d30e28571517073a663ca846c
|
|
| MD5 |
d6575d99c260b66a9b73c22edfc7a4c7
|
|
| BLAKE2b-256 |
879f5aed9ea35cd0a60c848886eb7c387263ace26bea07bcc41a43f2bce2ed86
|