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.
It also supports env files (let it be .json, .env or even .yaml)
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="mongodb://localhost:27017", collection_or_table_name="env_variables")
# or pass a database client client
client = MongoClient(...)
env_manager = ENVRX(env_file=".env", database=client, 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
(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="mongodb://localhost:27017", collection_or_table_name="env_variables")
# or if you have a database client
client = MongoClient(...)
env_manager = ENVRX(env_file=".env", database=client, 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
Database wise Examples can be found here.
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.3.tar.gz
.
File metadata
- Download URL: envrx-0.0.3.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed55a1ee1f7c27fe1fd92c58189058a70647ba229558fda6afe75af4988b263f |
|
MD5 | ee7d7244f510766431885fd0bf1bb935 |
|
BLAKE2b-256 | d337a4abfe793d0d418581ae3cf6aa251bb772aaf24cf16961ac755415b579b4 |
File details
Details for the file envrx-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: envrx-0.0.3-py3-none-any.whl
- Upload date:
- Size: 18.8 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 | 2ed61635945d0940d31dc0a9dfcd9a6d5f6a05a3c831447f21b360c70cdf7579 |
|
MD5 | e8f0b38e5669f459d363f9b20a7dffac |
|
BLAKE2b-256 | f6bc63864cd0a6e4a7dc565908721f7a4733fe0338cc268c6c0e955898732951 |