Metadata-Version: 2.4
Name: paraboloski-dotenv
Version: 0.1.0
Summary: Minimal environment variable helpers with explicit failure semantics.
Author-email: Paraboloski <andreapetracca155@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Andrea Petracca
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.12
Description-Content-Type: text/markdown

# paraboloski-dotenv

Helpers minimali per la lettura delle variabili d'ambiente con semantica di fallimento esplicita. Niente dipendenze, niente `load_dotenv`, niente classi.

## Installazione

### PyPI
```bash
uv add paraboloski-dotenv
pip install paraboloski-dotenv
```

### GitHub
```bash
uv add git+https://github.com/paraboloski/snippet-toolbox/python#subdirectory=snippet/dotenv
```

## Quando usarla

Ideale per qualsiasi applicazione che legge configurazione dall'ambiente: connessioni a database, chiavi API, URL di servizi esterni. Invece di disseminare `os.getenv` con controlli `None` nel codice, il fallimento diventa esplicito e centralizzato.

## Utilizzo

```python
from dotenv import env, require, EnvironmentError
```

### `require` — variabile obbligatoria

Se la variabile è assente il processo termina immediatamente con codice `1`, stampando un messaggio diagnostico su `stderr`. Ispirato al `panic()` di Go.

```python
POSTGRES_URL  = require("POSTGRES_URL")
POSTGRES_USER = require("POSTGRES_USER")
POSTGRES_PASS = require("POSTGRES_PASS")
```

```
[PANIC] Missing environment variable: 'POSTGRES_URL'
# il processo termina con codice 1
```

### `env` — variabile opzionale

Solleva `EnvironmentError` se la variabile è assente e non è stato fornito un default. Usa `env` quando vuoi decidere tu come gestire l'assenza.

```python
# Obbligatoria — solleva EnvironmentError se mancante
postgres_url = env("POSTGRES_URL")

# Opzionale con default
pool_size    = int(env("POSTGRES_POOL_SIZE", "10"))
conn_timeout = int(env("POSTGRES_CONN_TIMEOUT", "30"))
```

### Gestisci l'assenza con `try/except`

```python
try:
    postgres_url = env("POSTGRES_URL")
    db = connect(postgres_url)
except EnvironmentError:
    db = None  # salta la connessione in locale
```

### Propagazione come errore di dominio

```python
try:
    postgres_url = env("POSTGRES_URL")
except EnvironmentError as e:
    raise RuntimeError("Impossibile connettersi a Postgres: URL non configurata.") from e
```

## `env` vs `require`

| | `env` | `require` |
|---|---|---|
| Variabile assente | solleva `EnvironmentError` | termina il processo |
| Default supportato | ✅ | ❌ |
| Recuperabile | ✅ | ❌ |
| Uso tipico | config opzionale | secrets / config critica |