Metadata-Version: 2.4
Name: envguard-check
Version: 0.1.1
Summary: Validate your environment variables before your app crashes
License: MIT
Project-URL: Homepage, https://github.com/shahabRDZ/envguard
Project-URL: Repository, https://github.com/shahabRDZ/envguard
Keywords: environment,validation,env,dotenv,config,devops
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

<!-- Downloads: https://pepy.tech/project/envguard-check -->
<h1 align="center">envguard</h1>

<p align="center">
  <strong>Validate your environment variables before your app crashes</strong>
</p>

<p align="center">
  <img src="https://img.shields.io/pypi/v/envguard?color=blue" alt="PyPI" />
  <img src="https://img.shields.io/badge/python-3.10+-blue?logo=python&logoColor=white" alt="Python" />
  <img src="https://img.shields.io/badge/dependencies-zero-brightgreen" alt="Zero deps" />
  <img src="https://img.shields.io/badge/license-MIT-green" alt="License" />
</p>

---

## The Problem

Your `.env` file has a typo. You won't know until your app crashes at 3 AM in production.

```
DATABSE_URL=...   # typo → app starts → crashes 2 hours later on first DB call
SECRET_KEY=       # empty → auth silently broken
DEBUG=maybe       # not a boolean → who knows what happens
```

## The Solution

```bash
pip install envguard-check
```

Check everything **before** your app starts:

```python
from envguard import guard

# App won't start until all vars are valid
guard(
    DATABASE_URL="url",
    REDIS_URL="url",
    SECRET_KEY="str",
    DEBUG="bool",
    PORT="int",
)
```

If anything is wrong, you get a clear error and the app **refuses to start**:

```
Environment validation failed:

  ✗ MISSING: DATABASE_URL is required but not set
  ✗ TYPE: PORT='abc' is not a valid integer
  ✗ TYPE: DEBUG='maybe' is not a valid boolean

  3 error(s) found. Fix your .env file and try again.
```

## Features

### Type Validation

```python
from envguard import check_env, EnvVar

check_env([
    EnvVar(name="PORT", type="int"),           # must be integer
    EnvVar(name="RATE", type="float"),          # must be float
    EnvVar(name="DEBUG", type="bool"),          # true/false/1/0/yes/no
    EnvVar(name="API_URL", type="url"),         # must start with http(s)://
    EnvVar(name="ADMIN_EMAIL", type="email"),   # must contain @ and domain
])
```

### Choices

```python
check_env([
    EnvVar(name="ENV", choices=["development", "staging", "production"]),
    EnvVar(name="LOG_LEVEL", choices=["DEBUG", "INFO", "WARNING", "ERROR"]),
])
```

### Pattern Matching

```python
check_env([
    EnvVar(name="STRIPE_KEY", pattern=r"^sk_(live|test)_"),
    EnvVar(name="AWS_REGION", pattern=r"^[a-z]{2}-[a-z]+-\d$"),
])
```

### Defaults

```python
check_env([
    EnvVar(name="PORT", type="int", default="8000"),
    EnvVar(name="DEBUG", type="bool", default="false"),
])
```

### Optional Variables

```python
check_env([
    EnvVar(name="SENTRY_DSN", required=False),  # won't fail if missing
])
```

### Minimum Length

```python
check_env([
    EnvVar(name="SECRET_KEY", min_length=32),  # must be at least 32 chars
])
```

## Quick Start with `guard()`

The `guard()` function is a one-liner shorthand:

```python
from envguard import guard

guard(
    DATABASE_URL="url",
    REDIS_URL="url",
    SECRET_KEY="str",
    DEBUG="bool",
)
```

## Zero Dependencies

`envguard` uses only Python standard library. No bloat.

## License

MIT
