Skip to content

Commit

Permalink
EnvrX | v0.0.1 | Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
StarkGang committed Dec 17, 2023
0 parents commit 1446f8b
Show file tree
Hide file tree
Showing 9 changed files with 1,263 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish to PyPI

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Check commit message
run: |
if [[ $(git log -1 --pretty=%B) =~ v[0-9]+\.[0-9]+ ]]; then
echo "Commit message contains version pattern. Proceeding with build and publish."
else
echo "Warning: Commit message does not contain version pattern. Skipping version-specific actions."
fi
- name: Build and publish
if: success() # Only run if the check passed
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
echo "Building and publishing to PyPI..."
python setup.py sdist bdist_wheel
twine upload dist/*
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
envrx/__pycache__/__init__.cpython-311.pyc
*.pyc
*.db
*.env
test.py
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 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](#installation)
- [Usage](#usage)
- [Class Initialization](#class-initialization)
- [Loading Environment](#loading-environment)
- [Database Operations](#database-operations)
- [Examples](#examples)
- [License](#license)

## Installation

```bash
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

```python
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.

```python
# 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.

```python
# 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.

```python
# 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](https://github.com/Starkgang/Envrx/LICENSE).
13 changes: 13 additions & 0 deletions envrx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (C) 2023-present by StarkGang@Github, < https://github.com/StarkGang >.
#
# This file is part of < https://github.com/StarkGang/Envrx > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/StarkGang/Envrx/blob/main/LICENSE >
#
# All rights reserved.

from .envrx import *
from .exceptions import *


__version__ = "0.0.1"
Loading

0 comments on commit 1446f8b

Please sign in to comment.