Skip to main content

Lightweight policy-driven API protection and guardrails library

Project description

Hexarch Guardrails Python SDK

Lightweight policy-driven API protection for students, solo developers, and hackathons.

Installation

pip install hexarch-guardrails

Quick Start

1. Create a policy file (hexarch.yaml)

policies:
  - id: "api_budget"
    description: "Protect against overspending"
    rules:
      - resource: "openai"
        monthly_budget: 10
        action: "warn_at_80%"

  - id: "rate_limit"
    description: "Prevent API abuse"
    rules:
      - resource: "*"
        requests_per_minute: 100
        action: "block"

  - id: "safe_delete"
    description: "Require confirmation for destructive ops"
    rules:
      - operation: "delete"
        action: "require_confirmation"

2. Use in your code

from hexarch_guardrails import Guardian

# Initialize (auto-discovers hexarch.yaml)
guardian = Guardian()

# Protect API calls
@guardian.check("api_budget")
def call_openai(prompt):
    import openai
    return openai.ChatCompletion.create(
        model="gpt-4",
        messages=[{"role": "user", "content": prompt}]
    )

# Use it
response = call_openai("Hello AI!")

Features

  • Zero-config - Auto-discovers hexarch.yaml
  • Decorator-based - Drop in @guardian.check(policy_id)
  • Policy-driven - YAML-based rules, no code changes
  • Local-first - Works offline or with local OPA
  • Pluggable - Works with any API/SDK

Examples

Budget Protection (OpenAI)

@guardian.check("api_budget")
def expensive_operation():
    # This call is protected by budget limits
    return openai.ChatCompletion.create(model="gpt-4", ...)

Rate Limiting

@guardian.check("rate_limit")
def send_discord_message(msg):
    return client.send(msg)

Safe File Operations

@guardian.check("safe_delete")
def delete_file(path):
    os.remove(path)

Documentation

License

MIT © Noir Stack LLC

See LICENSE for full details.

MIT

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

hexarch_guardrails-0.1.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

hexarch_guardrails-0.1.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file hexarch_guardrails-0.1.0.tar.gz.

File metadata

  • Download URL: hexarch_guardrails-0.1.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for hexarch_guardrails-0.1.0.tar.gz
Algorithm Hash digest
SHA256 79ea280078c0646718d2afe128af7e252b9f684d685d22e8ef995baa42d0bb82
MD5 b53a9ed9da7c251c6013eb1cb14306fa
BLAKE2b-256 57dfbe3912945a3ddd67aa3128f61cffe9027b9f768c5aace8ea2b0112ec66f8

See more details on using hashes here.

File details

Details for the file hexarch_guardrails-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hexarch_guardrails-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9e70240aaeab7fdaa15dff8fe2859f748cce4d30aa0364aa92763e491cdc59c
MD5 c2dfca8c8e6c6ae0c17bec2b49884b72
BLAKE2b-256 21668a3c829e70c45f05a629d0c72f80c7ff7958dae1764704c4cd2316bef8ea

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