Metadata-Version: 2.3
Name: turboenv
Version: 0.2.0a1
Summary: TurboEnv is a Python library that provides a simple and efficient way to manage environment variables in your applications. It allows you to easily load environment variables from .env files, access them in your code, and handle different environments (development, testing, production) with ease.
Author: John Pendenque
Author-email: John Pendenque <pendenquejohn@gmail.com>
License: MIT
Classifier: Development Status :: 1 - Planning
Classifier: Operating System :: POSIX
Classifier: Operating System :: Unix
Classifier: Operating System :: Microsoft :: Windows
Classifier: Intended Audience :: Developers
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.14
Classifier: Natural Language :: English
Classifier: Operating System :: Microsoft :: Windows :: Windows 11
Classifier: Operating System :: MacOS
Requires-Dist: pydantic>=2.13.4
Maintainer: John Pendenque
Maintainer-email: John Pendenque <pendenquejohn@gmail.com>
Requires-Python: >=3.13
Project-URL: Changelog, https://github.com/Zadigo/turboenv/blob/main/CHANGELOG.md
Project-URL: Documentation, https://github.com/Zadigo/turboenv/wiki
Project-URL: Homepage, https://github.com/Zadigo/turboenv
Project-URL: Repository, https://github.com/Zadigo/turboenv.git
Description-Content-Type: text/markdown

# Turbo Env

TurboEnv is a Python library that provides a simple and efficient way to manage environment variables in your applications. It allows you to easily load environment variables from .env files, access them in your code, and handle different environments (development, testing, production) with ease.

## Installation

```Shell
pip install turboenv
```

## Loading Environment variables

## Automatic detection

When `load_envs` is first called, it looks for any `.env` located in the absolute path of the file that is calling it. If it finds one, it loads the environment variables from that file in the `default` namespace.

```python
from turboenv import TurboEnv

env = TurboEnv()
env.load_envs()
```

You can also specify the path to the `.env` file and the namespace you want to load it into.

```python
from turboenv import TurboEnv

env = TurboEnv()
env.load_envs('path/to/.env')

env.string('DB_USER')  # Accesses the DB_USER variable from the default namespace
```

## Accessing Environment Variables

Once the environment variables are loaded, you can access them in multiple different manners including typecasting their values to a specific one:

### Get method

Tries to get the value of the environment variable with the given name. If the variable is not found, an `exceptions.MissingEnvVariableError` is raised.

```python
db_user = env.get("DB_USER")
db_password = env.get("DB_PASSWORD")
```

### Boolean - Type Casting

Returns the boolean value of the environment variable with the given name:

```python
db_password = env.boolean("USE_DB")
```

### String - Type Casting

Returns the string value of the environment variable with the given name:

```python
db_password = env.string("DB_PASSWORD")
```

### Array - Type Casting

Returns a list of strings by splitting the value of the environment variable with the given name using a specified separator (default is comma):

```python
allowed_hosts = env.array("ALLOWED_HOSTS", cast=str)
```

### String List - Type Casting

Returns a list of strings by splitting the value of the environment variable with the given name using a specified separator (default is comma):

```python
allowed_hosts = env.str_list("ALLOWED_HOSTS")
```

### Integer List - Type Casting

Returns a list of integers by splitting the value of the environment variable with the given name using a specified separator (default is comma):

```python
allowed_ports = env.int_list("ALLOWED_PORTS")
```

### Domain List - Type Casting

Returns a list of domain names by splitting the value of the environment variable with the given name using a specified separator (default is comma):

```python
allowed_domains = env.domain_list("ALLOWED_DOMAINS")
```

### URL List - Type Casting

Returns a list of URLs by splitting the value of the environment variable with the given name using a specified separator (default is comma):

```python
allowed_urls = env.url_list("ALLOWED_URLS")
```

### Secret - Type Casting

Returns the value of the environment variable with the given name, decoded from base64:

```python
db_password = env.secret("DB_PASSWORD")
```

### Path - Type Casting

Returns a `Path` object representing the path specified by the environment variable with the given name:

```python
config_path = env.path("CONFIG_PATH")
```

> [!NOTE]
> The secret value should already be encoded in base64 or this will raise an error.

## Conditionals

Conditionals are used to guarantee the integrity of your environment variables by checking if they meet certain conditions. 
When the conditions are not met, an exception is raised.

### Depends On

Requires the presence of the specified environment variable in the environment.

```python
env.conditional("DB_USER").depends_on(values=["DB_PASSWORD"])
```

> [!CAUTION]
> It does not check the actual values of the environment variables, only their presence.

### To Be

Requires the value of the environment variable to be equal to a specified value.

```python
env.conditional("DB_USER").to_be("admin")
```

### Not To Be

Requires the value of the environment variable to not be equal to a specified value.

```python
env.conditional("DB_PASSWORD").not_to_be("password")
```

### To Exist

Requires the environment variable to be present.

> [!CAUTION]
> This does not check if the value of the environment variable is empty or not, it only checks if it is present in the environment.

```python
env.conditional("DB_USER").to_exist()
```

### To Not Be Empty

Requires the value of the environment variable to not be empty.

```python
env.conditional("DB_PASSWORD").to_not_be_empty()
```

### To Contain

Requires the value of the environment variable to contain a specified substring.

```python
env.conditional("ALLOWED_HOSTS").to_contain("example.com")
```

### Path To Exist

Requires the value of the environment variable to be a valid path that exists in the file system.

```python
env.conditional("CONFIG_PATH").path_to_exist()
```

# Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any suggestions or find any bugs.


To run the tests, use the following command:

```bash
pytest
```

# License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
