Skip to main content

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.

Metadata

Release files for envrx 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for envrx 0.0.4
File Size Uploaded
envrx-0.0.4.tar.gz 20.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for envrx 0.0.4
File Interpreter ABI Platform
envrx-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 43.9 kB

Release files / envrx-0.0.4.tar.gz

Download URL envrx-0.0.4.tar.gz
Size 20.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f7610367625b22813e028a26dc7f5d4079a36ea158f58bb0a8e3205411a6749b
BLAKE2b-256 checksum
How to use checksums
f1e41ad63e5275da95b3c2c409c6dab765f35cbe7ea333fc944f4ebebd595476
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / envrx-0.0.4-py3-none-any.whl

Download URL envrx-0.0.4-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e900689feb120b70a6f9d5d4c93f080d3904012c350d029b914a4179ea4227f1
BLAKE2b-256 checksum
How to use checksums
6f44ce9b69641a5c410ccbb00db0d9fc8bafc67219875b15fae772fd45514c80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page