envvalidator


Nameenvvalidator JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/Sekiraw/Envvalidator
Summaryenvvalidator description
upload_time2025-02-21 12:38:21
maintainerNone
docs_urlNone
authorQiyaya
requires_pythonNone
licenseApache-2.0
keywords env validator validate environment
VCS
bugtrack_url
requirements setuptools
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # EnvValidator

EnvValidator is a lightweight Python library that helps validate environment variables against a predefined schema. It ensures that required variables exist, follow the correct type or format, and falls back to system environment variables when an .env file is missing.

---

## Features

- Schema-Based Validation - Define expected environment variables and their types (string, int, bool, regex).
- Automatic Fallback - If no .env file is found, it retrieves values from system environment variables.
- Regex Support - Enforce custom formats (e.g., API keys, UUIDs).
- Error Handling - Provides clear error messages when validation fails.
- Lightweight & Fast - Minimal overhead with a simple API.

---

## Requirements

- Python 3.x (recommended: 3.7 or higher)

---

## Installation

Install the package using pip:

```bash
pip install envvalidator
```

## Usage
Here is an example of how to use EnvValidator:

```python

# Define the expected schema
schema = {
    "DATABASE_URL": "string",
    "DEBUG": "bool",
    "PORT": "int",
    "API_KEY": {"regex": r"^[A-Za-z0-9]{32}$"}  # Ensure 32-character API key format
}

try:
    ENV = envvalidator.validate_env(".env", schema)
    print(ENV)
except ValueError as e:
    print("Configuration error:", e)
```
## Output Example
If .env contains:
```ini
DATABASE_URL=postgres://user:pass@localhost:5432/db
DEBUG=true
PORT=8080
API_KEY=1234567890abcdef1234567890abcdef
```
The output would be:
```plaintext
{
    "DATABASE_URL": "postgres://user:pass@localhost:5432/db",
    "DEBUG": "true",
    "PORT": "8080",
    "API_KEY": "1234567890abcdef1234567890abcdef"
}
```
If a required variable is missing or does not match the expected type, an error is raised.

## How It Works
1. Reads the .env file (if available).
2. Parses key-value pairs and trims whitespace.
3. Checks each variable against the schema:
    - If defined in .env, it is validated.
    - If missing, it looks in system environment variables.
    - If validation fails, an error is raised.
4. Returns a dictionary of validated environment variables.

## Limitations
- Does not support deeply nested configurations (e.g., JSON-like structures).
- Assumes all values are stored as strings in environment variables.

## Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.

## Local Development
To set up a local development environment, follow these steps:

1. Create and activate a virtual environment:
    ```bash
    python -m venv venv
    source venv/bin/activate  # macOS/Linux
    venv\Scripts\activate     # Windows
    pip install -r requirements.txt
    ```
2. Build & install the project
    ```bash
    python setup.py build
    python setup.py install
    ```
3. Run an example script to test:
    ```bash
    python examples/example.py
    ```
The module is now installed in the virtual environment. You can test it by running the example script:

```bash
python examples/example.py
```


## License
This project is licensed under the Apache-2.0 License. See the LICENSE file for details.

## Author
Developed by Qiyaya

## Acknowledgements
Thanks to the Python (and ...) development communities for providing tools and resources to make this project possible.

```vbnet
This styling ensures clarity, proper sectioning, and good readability. Let me know if you`d like any further adjustments!
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Sekiraw/Envvalidator",
    "name": "envvalidator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "env, validator, validate, environment",
    "author": "Qiyaya",
    "author_email": "v2020.bohus.peter@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/20/92/e9166a0b06402ef7c49fd9751bdf04570557db3e5ffa349e89d0237f50bb/envvalidator-1.0.1.tar.gz",
    "platform": null,
    "description": "# EnvValidator\r\n\r\nEnvValidator is a lightweight Python library that helps validate environment variables against a predefined schema. It ensures that required variables exist, follow the correct type or format, and falls back to system environment variables when an .env file is missing.\r\n\r\n---\r\n\r\n## Features\r\n\r\n- Schema-Based Validation - Define expected environment variables and their types (string, int, bool, regex).\r\n- Automatic Fallback - If no .env file is found, it retrieves values from system environment variables.\r\n- Regex Support - Enforce custom formats (e.g., API keys, UUIDs).\r\n- Error Handling - Provides clear error messages when validation fails.\r\n- Lightweight & Fast - Minimal overhead with a simple API.\r\n\r\n---\r\n\r\n## Requirements\r\n\r\n- Python 3.x (recommended: 3.7 or higher)\r\n\r\n---\r\n\r\n## Installation\r\n\r\nInstall the package using pip:\r\n\r\n```bash\r\npip install envvalidator\r\n```\r\n\r\n## Usage\r\nHere is an example of how to use EnvValidator:\r\n\r\n```python\r\n\r\n# Define the expected schema\r\nschema = {\r\n    \"DATABASE_URL\": \"string\",\r\n    \"DEBUG\": \"bool\",\r\n    \"PORT\": \"int\",\r\n    \"API_KEY\": {\"regex\": r\"^[A-Za-z0-9]{32}$\"}  # Ensure 32-character API key format\r\n}\r\n\r\ntry:\r\n    ENV = envvalidator.validate_env(\".env\", schema)\r\n    print(ENV)\r\nexcept ValueError as e:\r\n    print(\"Configuration error:\", e)\r\n```\r\n## Output Example\r\nIf .env contains:\r\n```ini\r\nDATABASE_URL=postgres://user:pass@localhost:5432/db\r\nDEBUG=true\r\nPORT=8080\r\nAPI_KEY=1234567890abcdef1234567890abcdef\r\n```\r\nThe output would be:\r\n```plaintext\r\n{\r\n    \"DATABASE_URL\": \"postgres://user:pass@localhost:5432/db\",\r\n    \"DEBUG\": \"true\",\r\n    \"PORT\": \"8080\",\r\n    \"API_KEY\": \"1234567890abcdef1234567890abcdef\"\r\n}\r\n```\r\nIf a required variable is missing or does not match the expected type, an error is raised.\r\n\r\n## How It Works\r\n1. Reads the .env file (if available).\r\n2. Parses key-value pairs and trims whitespace.\r\n3. Checks each variable against the schema:\r\n    - If defined in .env, it is validated.\r\n    - If missing, it looks in system environment variables.\r\n    - If validation fails, an error is raised.\r\n4. Returns a dictionary of validated environment variables.\r\n\r\n## Limitations\r\n- Does not support deeply nested configurations (e.g., JSON-like structures).\r\n- Assumes all values are stored as strings in environment variables.\r\n\r\n## Contributing\r\nContributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.\r\n\r\n## Local Development\r\nTo set up a local development environment, follow these steps:\r\n\r\n1. Create and activate a virtual environment:\r\n    ```bash\r\n    python -m venv venv\r\n    source venv/bin/activate  # macOS/Linux\r\n    venv\\Scripts\\activate     # Windows\r\n    pip install -r requirements.txt\r\n    ```\r\n2. Build & install the project\r\n    ```bash\r\n    python setup.py build\r\n    python setup.py install\r\n    ```\r\n3. Run an example script to test:\r\n    ```bash\r\n    python examples/example.py\r\n    ```\r\nThe module is now installed in the virtual environment. You can test it by running the example script:\r\n\r\n```bash\r\npython examples/example.py\r\n```\r\n\r\n\r\n## License\r\nThis project is licensed under the Apache-2.0 License. See the LICENSE file for details.\r\n\r\n## Author\r\nDeveloped by Qiyaya\r\n\r\n## Acknowledgements\r\nThanks to the Python (and ...) development communities for providing tools and resources to make this project possible.\r\n\r\n```vbnet\r\nThis styling ensures clarity, proper sectioning, and good readability. Let me know if you`d like any further adjustments!\r\n```\r\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "envvalidator description",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/Sekiraw/Envvalidator"
    },
    "split_keywords": [
        "env",
        " validator",
        " validate",
        " environment"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "df5df3e78749f95819fa2ba2ff4f92b790584834ff4004214e6f966cdd9c14b3",
                "md5": "cd10cba19038dc617ee567dabe408197",
                "sha256": "de241c972462a2eb673528ee9b3987471b82b0e0612fb95904c8b990498c370a"
            },
            "downloads": -1,
            "filename": "envvalidator-1.0.1-cp313-cp313-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "cd10cba19038dc617ee567dabe408197",
            "packagetype": "bdist_wheel",
            "python_version": "cp313",
            "requires_python": null,
            "size": 45710,
            "upload_time": "2025-02-21T12:38:20",
            "upload_time_iso_8601": "2025-02-21T12:38:20.684598Z",
            "url": "https://files.pythonhosted.org/packages/df/5d/f3e78749f95819fa2ba2ff4f92b790584834ff4004214e6f966cdd9c14b3/envvalidator-1.0.1-cp313-cp313-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2092e9166a0b06402ef7c49fd9751bdf04570557db3e5ffa349e89d0237f50bb",
                "md5": "372351263388fa00ff199b51be58b884",
                "sha256": "bb5ba606623df52075c1a23f16bc0bbe53785768f0dbdbffb97156034be5494e"
            },
            "downloads": -1,
            "filename": "envvalidator-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "372351263388fa00ff199b51be58b884",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8184,
            "upload_time": "2025-02-21T12:38:21",
            "upload_time_iso_8601": "2025-02-21T12:38:21.865985Z",
            "url": "https://files.pythonhosted.org/packages/20/92/e9166a0b06402ef7c49fd9751bdf04570557db3e5ffa349e89d0237f50bb/envvalidator-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-21 12:38:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Sekiraw",
    "github_project": "Envvalidator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "setuptools",
            "specs": []
        }
    ],
    "lcname": "envvalidator"
}
        
Elapsed time: 0.96040s