A package to manage environment variables with database and custom env file support.
Project description
ENVRX
ENVRX
is a Python class designed to manage environment variables seamlessly, providing support for various databases such as MongoDB, SQL, and Redis.
Table of Contents
Installation
pip install envrx
- If you are using mongodb for database:
pip install pymongo
- or If using postgreSQL
pip install psycopg2
- or If using Redis
pip install redis
- Sqlite uses
sqlite3
Usage
from envrx import ENVRX
import os
# Initialize ENVRX with optional parameters
env_manager = ENVRX(env_file=".env", database_url="mongodb://localhost:27017", collection_or_table_name="env_variables")
# Initialize the environment
env_manager.initialize()
# Access loaded env
print(os.getenv("env_from_db_or_file"))
Class Initialization
env_file
(Optional): Path to the environment file.database_url
(Optional): Database URL for MongoDB, SQL, or Redis.collection_or_table_name
(Optional): Name of the collection or table in the database.
# Example initialization
env_manager = ENVRX(env_file=".env", database_url="mongodb://localhost:27017", collection_or_table_name="env_variables")
Loading Environment
initialize()
: Initializes the class and loads environment variables from both the specified file and database.
# Example loading environment
env_manager.initialize()
- Please note that, all variables will be auto loaded when running this and can be accessed through
os.environ.get("foo_bar")
Database Operations
-
load_from_database()
: Loads environment variables from the specified database. -
get_env_from_database(key)
: Gets a specific environment variable from the database. -
get_all_env_from_database()
: Gets all environment variables from the database. -
load_env_to_database(key, value)
: Loads a new environment variable to the database. -
delete_env_from_database(key)
: Deletes an environment variable from the database. -
update_env_in_database(key, value)
: Updates an environment variable in the database.
# Example database operations
value = env_manager.get_env_from_database("KEY_NAME")
env_manager.load_env_to_database("NEW_KEY", "NEW_VALUE")
env_manager.delete_env_from_database("OLD_KEY")
env_manager.update_env_in_database("EXISTING_KEY", "UPDATED_VALUE")
Examples
No example has been made yet but you can always send a PR.
License
This project is licensed under the GPL V3.0.
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
File details
Details for the file envrx-0.0.1.tar.gz
.
File metadata
- Download URL: envrx-0.0.1.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 468da925e595c0501f40e3c55db958657c5824f9cbe9d63aa62d04b82383f6a1 |
|
MD5 | 13179ee96b269d4be33fb668e7ec64ae |
|
BLAKE2b-256 | dab293cc0655ac038450bb37ed2c244dba67b7f538722ea35a3b49ebdc2b6792 |
File details
Details for the file envrx-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: envrx-0.0.1-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23e9cc20ad1200238a7e06b8500c6fe3ee71b6e47ed92c0178d62537408007f6 |
|
MD5 | cb827cc89f575acee360e4c471c59143 |
|
BLAKE2b-256 | 1afc8eefe9a69c64b12f3a35ce8e61416d85bd250fd5e715d332e86f94001f46 |