Skip to main content

Hanzo IAM SDK - Identity and Access Management for Python

Project description

hanzoai-iam

Identity and Access Management SDK for the Hanzo ecosystem. Organization-aware multi-tenant IAM for the Hanzo ecosystem.

The PyPI distribution is hanzoai-iam; the import path is hanzo_iam.

Installation

pip install hanzoai-iam

With FastAPI integration:

pip install hanzoai-iam[fastapi]

With KMS support for certificate management:

pip install hanzoai-iam[kms]

Quick Start

from hanzo_iam import IAMClient, IAMConfig

config = IAMConfig(
    endpoint="https://iam.hanzo.ai",
    client_id="your-client-id",
    client_secret="your-client-secret",
    org_name="HANZO",
)

client = IAMClient(config)

# Get authorization URL for user login
auth_url = client.get_auth_url(redirect_uri="https://yourapp.com/callback")

# Exchange code for tokens
tokens = client.get_token(code="auth-code-from-callback")

# Get user info
user = client.get_user_info(access_token=tokens.access_token)

Organizations

Organization Endpoint Description
HANZO https://iam.hanzo.ai Hanzo AI platform
ZOO https://iam.zoo.dev Zoo Labs Foundation
LUX https://iam.lux.network Lux blockchain network
PARS https://iam.pars.dev Pars development platform

Environment Variables

One canonical prefix — IAM_*. No upstream-brand aliases, no per-org variants.

# Required
IAM_ENDPOINT=https://hanzo.id
IAM_CLIENT_ID=your-client-id
IAM_CLIENT_SECRET=your-client-secret

# Optional (defaults shown)
IAM_ORG=hanzo
IAM_APP=app
IAM_CERT=path/to/cert.pem    # PEM file or inline PEM content

FastAPI Integration

from fastapi import FastAPI, Depends
from hanzo_iam.fastapi import IAMAuth, get_current_user
from hanzo_iam import IAMConfig, User

app = FastAPI()

config = IAMConfig.from_env()
auth = IAMAuth(config)

@app.get("/protected")
async def protected_route(user: User = Depends(auth.require_user)):
    return {"user": user.name, "org": user.owner}

@app.get("/optional")
async def optional_auth(user: User | None = Depends(auth.optional_user)):
    if user:
        return {"message": f"Hello, {user.name}"}
    return {"message": "Hello, anonymous"}

Client Credentials Flow

For service-to-service authentication:

from hanzo_iam import IAMClient, IAMConfig

config = IAMConfig(
    endpoint="https://iam.hanzo.ai",
    client_id="service-client-id",
    client_secret="service-client-secret",
    org_name="HANZO",
)

client = IAMClient(config)

# Get service token
tokens = client.get_client_credentials_token()

# Use token for API calls
headers = {"Authorization": f"Bearer {tokens.access_token}"}

Async Client

import asyncio
from hanzo_iam import AsyncIAMClient, IAMConfig

async def main():
    config = IAMConfig.from_env()
    client = AsyncIAMClient(config)

    # All methods are async
    tokens = await client.get_client_credentials_token()
    user = await client.get_user_info(tokens.access_token)

    print(f"Authenticated as: {user.name}")

asyncio.run(main())

API Reference

Method Description
get_auth_url(redirect_uri, state, scope) Generate OAuth authorization URL
get_token(code) Exchange authorization code for tokens
refresh_token(refresh_token) Refresh access token
get_client_credentials_token() Get token via client credentials flow
get_user_info(access_token) Get user info from access token
parse_jwt(token) Parse and validate JWT claims
get_user(user_id) Get user by ID
get_users() List all users in organization
create_user(user) Create new user
update_user(user) Update existing user
delete_user(user_id) Delete user
get_organizations() List organizations
get_organization(name) Get organization by name

License

Apache-2.0

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_iam-1.30.0.tar.gz (45.9 kB view details)

Uploaded Source

Built Distribution

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

hanzo_iam-1.30.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file hanzo_iam-1.30.0.tar.gz.

File metadata

  • Download URL: hanzo_iam-1.30.0.tar.gz
  • Upload date:
  • Size: 45.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for hanzo_iam-1.30.0.tar.gz
Algorithm Hash digest
SHA256 ed96b7a08fb57c4e2acc36e78c919d267749242e43de1db8c408dbe2d8ca7d06
MD5 0724a9be2a36b394806d2b187ce9e29f
BLAKE2b-256 5c389076364ac297be5d61f39644b35ee2cdd0d68fd8acb1e8d6266b3747d926

See more details on using hashes here.

File details

Details for the file hanzo_iam-1.30.0-py3-none-any.whl.

File metadata

  • Download URL: hanzo_iam-1.30.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for hanzo_iam-1.30.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9e2536a2cb3c0ac780249df720e71c6a67b4b53946aa9599f5bd27656822bf2
MD5 05e65309fa2bfaa4f83650e33448320b
BLAKE2b-256 adc561d6d8d1c73ea5a51b522120e306a7d3f0c1f846df6a920d077a8a2b961a

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