Skip to main content

Official Humanos API SDK for Python with automatic request signing and webhook verification

Project description

Humanos SDK for Python

Official Python SDK for the Humanos API. Provides automatic request signing, webhook verification and decryption, and full API access for credential management.

PyPI version License: MIT

Features

  • Automatic Request Signing - All API requests are signed with HMAC-SHA256
  • Webhook Verification - Verify signatures and decrypt encrypted payloads
  • Type Hints - Full type annotations with Pydantic models
  • Simple API - Clean interface for all Humanos endpoints

Getting Started

1. Install the SDK

pip install humanos

2. Create an Account

Sign up at humanos.id and create your organization.

3. Get Your API Keys

In the Humanos Dashboard, go to Settings > API Keys and copy:

  • API Key - Used to authenticate requests
  • Signature Secret - Used to sign requests with HMAC-SHA256

4. Get Your Webhook Keys

In the Humanos Dashboard, go to Settings > Webhooks and copy:

  • Webhook Signature Secret - Used to verify incoming webhook signatures
  • Webhook Encryption Secret - Used to decrypt webhook payloads
  • Webhook Encryption Salt - Used alongside the encryption secret

5. Initialize the Client

from humanos_sdk import HumanosClient, HumanosClientConfig

client = HumanosClient(HumanosClientConfig(
    base_path="https://api.humanos.id",
    api_key=os.environ["HUMANOS_API_KEY"],
    signature_secret=os.environ["HUMANOS_SIGNATURE_SECRET"],
))

6. Make Your First API Call

Fetch all your credential requests:

response = client.requests.get_requests()
print(response.data)

Usage Examples

Create a Credential Request

Send a credential request to one or more contacts using pre-configured resources:

from humanos_sdk import GenerateRequestDto

request = client.requests.generate(GenerateRequestDto(
    contacts=["user@example.com"],
    security_level="CONTACT",
    resources_ids=["your-resource-id"],
))

print("Request ID:", request.id)
print("Credentials:", request.credentials)

You can also use group IDs to include all resources in a group:

request = client.requests.generate(GenerateRequestDto(
    contacts=["user@example.com"],
    security_level="CONTACT",
    group_ids=["your-group-id"],
))

Or provide inline credential data directly:

from humanos_sdk import CredentialDto, MandateDataDto, MandateDataDtoValue

request = client.requests.generate(GenerateRequestDto(
    contacts=["user@example.com"],
    security_level="CONTACT",
    credentials=[
        CredentialDto(
            scope="onboarding",
            type="JSON",
            name="Service Agreement",
            data=[
                MandateDataDto(label="Company", type="string", value=MandateDataDtoValue("Acme Corp")),
                MandateDataDto(label="Plan", type="string", value=MandateDataDtoValue("Enterprise")),
            ],
        ),
    ],
))

Receive Webhooks

Humanos sends webhook events when credentials are signed, identity checks complete, or OTPs fail. Payloads are encrypted and signed.

The SDK provides create_flask_webhook_handler which handles signature verification and payload decryption automatically:

from flask import Flask
from humanos_sdk import create_flask_webhook_handler, WebhookConfig

app = Flask(__name__)

webhook_config = WebhookConfig(
    signature_secret=os.environ["HUMANOS_WEBHOOK_SIGNATURE_SECRET"],
    encryption_secret=os.environ["HUMANOS_WEBHOOK_ENCRYPTION_SECRET"],
    encryption_salt=os.environ["HUMANOS_WEBHOOK_ENCRYPTION_SALT"],
)

def on_webhook(payload):
    print("Event type:", payload.get("eventType"))

    event_type = payload.get("eventType")
    if event_type == "credential":
        print("Credential signed:", payload.get("requestId"))
    elif event_type == "identity":
        print("Identity verified:", payload.get("requestId"))
    elif event_type == "otp.failed":
        print("OTP failed:", payload.get("requestId"))
    elif event_type == "test":
        print("Test event received")

app.add_url_rule(
    "/webhook",
    "webhook",
    create_flask_webhook_handler(webhook_config, on_webhook),
    methods=["POST"],
)

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=3000)

For local development, use ngrok to expose your server:

ngrok http 3000

Then set the ngrok URL (e.g. https://xxxx.ngrok-free.app/webhook) as your webhook URL in the Humanos Dashboard under Settings > Webhooks.

API Reference

Resources

# List resources
resources = client.resources.get_resources()

# List resource groups
groups = client.resources.get_groups()

Requests

# List requests
requests = client.requests.get_requests()

# Get request details
detail = client.requests.get_request_detail(request_id)

# Create a credential request
request = client.requests.generate(GenerateRequestDto(...))

# Cancel a request
client.requests.cancel_request(request_id)

# Resend OTP
client.requests.resend_otp(request_id, contact="user@example.com")

Users

from humanos_sdk import CreateSubjectDto, IdentityDto

# Create or update users
users = client.users.create([
    CreateSubjectDto(
        contact="user@example.com",
        internal_id="your-internal-id",
        identity=IdentityDto(
            full_name="John Doe",
            birth="1990-01-01",
            doc_id="123456789",
            country_alpha3="USA",
        ),
    )
])

Credentials

# Get credential by ID
credential = client.credentials.get_credential(credential_id)

# Get credential with PDF
credential = client.credentials.get_credential(credential_id, include_pdf=True)

Error Handling

The SDK raises ApiException for failed requests. The exception includes the HTTP status and response body:

from humanos_sdk import ApiException

try:
    request = client.requests.generate(GenerateRequestDto(...))
except ApiException as e:
    print(f"Status: {e.status}")
    print(f"Body: {e.body}")
except Exception as e:
    print(f"Error: {e}")

Documentation

Support

License

MIT License - see 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

humanos-1.0.2.tar.gz (58.4 kB view details)

Uploaded Source

Built Distribution

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

humanos-1.0.2-py3-none-any.whl (136.2 kB view details)

Uploaded Python 3

File details

Details for the file humanos-1.0.2.tar.gz.

File metadata

  • Download URL: humanos-1.0.2.tar.gz
  • Upload date:
  • Size: 58.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for humanos-1.0.2.tar.gz
Algorithm Hash digest
SHA256 7375007b76a1f44bbfdd92d27f8411d89cc773bceba52ae03a371ad63abdc909
MD5 46ff8e4103f7f31c0292bb32b06d8aa1
BLAKE2b-256 c390f881131a8d9dc385336595996a9d6e045a02ee21d5d1dd18538c65d4376c

See more details on using hashes here.

Provenance

The following attestation bundles were made for humanos-1.0.2.tar.gz:

Publisher: publish-python.yml on Humanos-App/humanos-sdks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file humanos-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: humanos-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 136.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for humanos-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9440b3c0e4d39417d413db7c8f6eaea30feb485edcee989c0e99cb4d87477087
MD5 ecb5628722b852616ab27c14598ee832
BLAKE2b-256 67e6c82db9e8ba94fc1c621d7372b684ab351b4b06005dfc8c2f161cdd7d761f

See more details on using hashes here.

Provenance

The following attestation bundles were made for humanos-1.0.2-py3-none-any.whl:

Publisher: publish-python.yml on Humanos-App/humanos-sdks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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