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
    
  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

      - 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.12.tar.gz (4.5 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.12-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: varsguard-0.0.12.tar.gz
  • Upload date:
  • Size: 4.5 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.12.tar.gz
Algorithm Hash digest
SHA256 502f6091102b7a01525d9cf87eff638db8ca62b58033fea2fd7f2333801f722b
MD5 f3edaccb028911f1b036273ecbb428f8
BLAKE2b-256 64b293fdcdf3b002d3df6570c84d8926d6d549ad3301b4267a73b18713a9cbd7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: varsguard-0.0.12-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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 f59da6220c3aae4ec34e7a42816cc0147a0c9c1496fbb3f08fe8788c223e30ad
MD5 57efcbc3a21e9d42b9725c0c3fa32eed
BLAKE2b-256 15515b1c0fd7bd90ba895932958e1297a22bb305b67884fc060168338b75b66a

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