-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1446f8b
Showing
9 changed files
with
1,263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Oops, something went wrong.