Skip to main content

Python wrapper for the VarsGuard CLI tool.

Project description

VarsGuard Python Wrapper

This is a Python wrapper for the VarsGuard library, enabling secure and efficient management of environment variables for Python projects. This wrapper allows you to use VarsGuard's functionality directly within your Python code, ensuring your environment variables are properly validated and managed according to best practices.

Prerequisites

Before using this wrapper, ensure that you have the varsguard CLI tool installed globally on your system. You can do this by running the following command:

npm install -g varsguard

This command installs the VarsGuard CLI globally on your machine, which is necessary for the wrapper to function correctly.

Installation

To install the VarsGuard Python Wrapper in your Python environment, you can use pip:

  1. Install the package from PyPI:

    pip install varsguard-wrapper
    
  2. Alternatively, you can clone the repository and install it locally for development purposes:

    git clone https://github.com/your-username/var-guard-python-wrapper.git
    cd var-guard-python-wrapper
    pip install .
    

Usage

Once the wrapper is installed, you can use it in your Python projects. Below are the available commands you can execute.

1. Generate .env.example File

Use the generate method to scan your codebase for environment variables and automatically generate a .env.example file.

from varsguard.cli import VarsGuard

# Generate .env.example from your codebase
VarsGuard.generate()

2. Validate .env File

Use the validate method to validate your .env file against the .env.example or a schema file. You can also pass a GitHub token and repository if needed for additional context.

from varsguard.cli import VarsGuard

# Validate your .env file
VarsGuard.validate(token="your_github_token", repo="owner/repo", schema_path="path/to/schema.json")

Commands Reference

generate()

  • Scans your codebase and generates a .env.example file.

validate(token, repo, schema_path)

  • Validates your .env file against the .env.example or a schema file.
  • Parameters:
    • token (str): GitHub token for accessing the repository (optional).
    • repo (str): GitHub repository in the format owner/repo (optional).
    • schema_path (str): Path to the schema file (optional).

CI/CD Integration

You can integrate VarsGuard validation into your CI/CD pipeline. The Python wrapper can be used to automatically validate environment variables during your build or deployment process. Here’s an example GitHub Actions workflow that uses the VarsGuard.validate() method to ensure that your .env file is correctly configured:

Example GitHub Actions Workflow

name: Validate .env File

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  validate:
    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.10'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install varsguard-wrapper

      - name: Validate .env file
        run: |
          python -c "from varsguard.cli import VarsGuard; VarsGuard.validate(token='${{ secrets.GITHUB_TOKEN }}', repo='owner/repo')"

Testing Locally

To test the wrapper locally before publishing, make sure you have the necessary dependencies installed and test it using the following steps:

  1. Clone the repository locally:

    git clone https://github.com/your-username/var-guard-python-wrapper.git
    cd var-guard-python-wrapper
    
  2. Install the Python dependencies:

    pip install -r requirements.txt
    
  3. Test your Python wrapper methods:

    from varsguard.cli import VarsGuard
    
    # Run generate method
    VarsGuard.generate()
    
    # Run validate method
    VarsGuard.validate(token="your_github_token", repo="owner/repo", schema_path="path/to/schema.json")
    

Contributing

We welcome contributions! If you would like to contribute to the VarsGuard Python Wrapper, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Commit your changes.
  4. Push the changes to your fork.
  5. Open a pull request with a description of your changes.

Please ensure that you have tested your changes locally before submitting a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

varsguard-0.0.10.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

varsguard-0.0.10-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file varsguard-0.0.10.tar.gz.

File metadata

  • Download URL: varsguard-0.0.10.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for varsguard-0.0.10.tar.gz
Algorithm Hash digest
SHA256 67a104f65c379990146d98143035bfc9d0ee37bc85a97bb9a968620958c3c699
MD5 0b2ec0c3b2f238f1429c5248f54cbd42
BLAKE2b-256 53b457d7ba4819744fe5dd7daacbb86b767ab443c7d71408f5c83831cee9ee79

See more details on using hashes here.

File details

Details for the file varsguard-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: varsguard-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for varsguard-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 1370b44bd81c4f712b4fb6df4fef54241ecd1cd58f2422a6d5bbb88c20ac2c18
MD5 3a2c3a6491576c6c9c709000b84489ce
BLAKE2b-256 cfc910b8095a618f47339e1b10a620e5ba3a7715fd8d11556cd5408c7702285c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page