Skip to main content

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_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

Database wise Examples can be found here.

License

This project is licensed under the GPL V3.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

envrx-0.0.2.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

envrx-0.0.2-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file envrx-0.0.2.tar.gz.

File metadata

  • Download URL: envrx-0.0.2.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for envrx-0.0.2.tar.gz
Algorithm Hash digest
SHA256 9aa173b516b5039ce7ccf2ba2a9cc5d5509a3a166feb4e9922f5a0880a774b9f
MD5 2fac4be2a1f811453950b90ffda7491b
BLAKE2b-256 90be29d7269c077ee9d9061c751ed152b90cd2c25f3278b13804f734daa1385a

See more details on using hashes here.

File details

Details for the file envrx-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: envrx-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for envrx-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 695438b7224fd7fc60d0850898beebcdceb7da82ce7498c65bb8782b565f00b8
MD5 e0626bd3c0a66db906049c6694bac00b
BLAKE2b-256 76e386117aae509a31659046815d5a018d2209f7ab05dd9ca3f14307083e4565

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page