Skip to main content

Generic API tool for calling any REST API via OpenAPI specs - search, explore, and dynamically use ANY API

Project description

hanzo-tools-api

Generic API tool for calling any REST API via OpenAPI specs.

Features

  • Credential Management: Securely store and manage API keys with env var fallback
  • OpenAPI Support: Parse OpenAPI 3.x specs to discover and call operations
  • Auto-Detection: Automatically detects credentials from environment variables
  • Multi-Provider: Built-in support for 30+ cloud providers
  • Raw Requests: Make raw HTTP requests when you need more control

Installation

pip install hanzo-tools-api

Quick Start

Using Environment Variables (Recommended)

Set your API keys as environment variables:

export CLOUDFLARE_API_TOKEN=your-token
export GITHUB_TOKEN=ghp_xxx
export STRIPE_API_KEY=sk_xxx

The tool automatically detects these when you make calls.

Using the Tool

from hanzo_tools.api import APITool

tool = APITool()

# List available providers and their status
await tool.call(ctx, action="list")

# Configure a provider manually
await tool.call(ctx, 
    action="config",
    provider="cloudflare",
    api_key="your-key"
)

# Load OpenAPI spec for a provider
await tool.call(ctx, action="spec", provider="cloudflare")

# List available operations
await tool.call(ctx, action="ops", provider="cloudflare", search="zones")

# Call an operation
await tool.call(ctx,
    action="call",
    provider="cloudflare",
    operation="listZones"
)

# Make a raw request
await tool.call(ctx,
    action="raw",
    provider="github",
    method="GET",
    path="/user/repos"
)

MCP Tool Usage

When registered with hanzo-mcp, use like:

api                                    # List all providers
api --action config --provider github --api_key ghp_xxx
api --action ops --provider cloudflare --search zones
api --action call --provider cloudflare --operation listZones
api --action raw --provider github --method GET --path /user/repos

Supported Providers

Built-in configurations for:

Provider Env Variables
Cloudflare CLOUDFLARE_API_TOKEN, CF_API_TOKEN
GitHub GITHUB_TOKEN, GH_TOKEN
Stripe STRIPE_API_KEY
OpenAI OPENAI_API_KEY
Anthropic ANTHROPIC_API_KEY
Vercel VERCEL_TOKEN
DigitalOcean DIGITALOCEAN_TOKEN, DO_TOKEN
Fly.io FLY_API_TOKEN
Supabase SUPABASE_API_KEY
AWS AWS_ACCESS_KEY_ID
GCP GOOGLE_API_KEY
Azure AZURE_API_KEY
Slack SLACK_TOKEN
Discord DISCORD_TOKEN
... and more

API Reference

Actions

  • list: Show all providers and their configuration status
  • config: Set credentials for a provider
  • delete: Remove credentials for a provider
  • spec: Load/refresh OpenAPI spec for a provider
  • ops: List available operations for a provider
  • call: Call an API operation by operation ID
  • raw: Make a raw HTTP request to any endpoint

Parameters

Parameter Type Description
action str Action to perform (default: "list")
provider str Provider name (e.g., "cloudflare")
api_key str API key for config action
api_secret str API secret (if needed)
account_id str Account/org ID
base_url str Override base URL
spec_url str URL to OpenAPI spec
operation str Operation ID for call action
params str JSON parameters
body str JSON request body
method str HTTP method for raw action
path str URL path for raw action
search str Search filter for ops action
tag str Tag filter for ops action

Credential Storage

Credentials are stored in ~/.hanzo/api/credentials.json with basic obfuscation. For production use, consider using system keyring or a secrets manager.

OpenAPI specs are cached in ~/.hanzo/api/specs/.

Adding Custom Providers

You can add any provider by providing a base URL and API key:

from hanzo_tools.api import get_credential_manager

cred_manager = get_credential_manager()
cred_manager.set_credential(
    provider="custom-api",
    api_key="your-key",
    base_url="https://api.custom.com/v1"
)

Then load a spec:

from hanzo_tools.api import get_client

client = await get_client(
    "custom-api",
    spec_url="https://api.custom.com/openapi.json"
)

Security Notes

  • API keys are stored with basic base64 obfuscation (not encryption)
  • Credentials file has restrictive permissions (0600)
  • Environment variables are preferred for sensitive credentials
  • Never commit credentials to version control

License

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

hanzo_tools_api-0.3.1.tar.gz (204.4 kB view details)

Uploaded Source

Built Distribution

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

hanzo_tools_api-0.3.1-py3-none-any.whl (134.7 kB view details)

Uploaded Python 3

File details

Details for the file hanzo_tools_api-0.3.1.tar.gz.

File metadata

  • Download URL: hanzo_tools_api-0.3.1.tar.gz
  • Upload date:
  • Size: 204.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for hanzo_tools_api-0.3.1.tar.gz
Algorithm Hash digest
SHA256 bab061526849f61234e0a2bdf1e8c02092374566125ad721abd322c3cf506b45
MD5 7769c9bf26179fd17843bc33ac7d82b5
BLAKE2b-256 b7a94277bf9752f043e4b42831468b1ae4e85a628612b6d6e9ecdcece8f98e63

See more details on using hashes here.

File details

Details for the file hanzo_tools_api-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hanzo_tools_api-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f9a26f3e195b6ec1c4ec049b7fb9003183a0717f8a217bf14156da43d6d6d15
MD5 c8b7d98e1d102d673293d975c39fba61
BLAKE2b-256 a65d6f00bbd79ecc3b0313cf7bd52d7c986fe7a8fa74d3f0052216b9bfbc5476

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