Skip to main content

Official Authensure SDK for Python - Electronic signature and document authentication platform

Project description

Authensure Python SDK

PyPI version Python Versions License: MIT

Official Python SDK for Authensure - the electronic signature and document authentication platform.

Features

  • 🔐 Full API Coverage - Access all Authensure API endpoints
  • 🐍 Type Hints - Complete type annotations with Pydantic models
  • Async Support - Native async/await for high-performance applications
  • 🔄 Automatic Retries - Built-in exponential backoff for transient errors
  • ⏱️ Rate Limit Handling - Automatic rate limit detection and backoff
  • 🔗 Webhook Verification - Easy webhook signature verification
  • 📁 File Uploads - Simplified document upload handling
  • 🐛 Debug Mode - Detailed logging for development

Installation

pip install authensure

Quick Start

from authensure import Authensure

# Initialize with API key
client = Authensure(api_key="your_api_key_here")

# Or with access token
client = Authensure.create_with_token("your_access_token")

# Create an envelope
envelope = client.envelopes.create(
    name="Contract Agreement",
    message="Please sign this document",
)

# Add a recipient
client.envelopes.add_recipient(
    envelope_id=envelope.id,
    email="signer@example.com",
    name="John Doe",
    role="signer",
)

# Send for signing
client.envelopes.send(envelope.id)

Async Usage

import asyncio
from authensure import Authensure

async def main():
    async with Authensure(api_key="your_api_key") as client:
        # Create envelope asynchronously
        envelope = await client.envelopes.create_async(
            name="Contract Agreement",
        )
        
        # Add recipients in parallel
        await asyncio.gather(
            client.envelopes.add_recipient_async(envelope.id, "alice@example.com", "Alice"),
            client.envelopes.add_recipient_async(envelope.id, "bob@example.com", "Bob"),
        )

asyncio.run(main())

Authentication

Using API Key

client = Authensure(api_key="your_api_key")

Using Email/Password Login

client = Authensure(access_token="temporary")

response = client.auth.login("user@example.com", "password")
# Token is automatically set for subsequent requests

Configuration Options

client = Authensure(
    api_key="your_api_key",              # API key for authentication
    access_token="your_token",           # JWT access token
    base_url="https://api.authensure.app/api",  # API base URL
    timeout=30.0,                        # Request timeout in seconds
    retry_attempts=3,                    # Number of retry attempts
    retry_delay=1.0,                     # Initial retry delay in seconds
    debug=False,                         # Enable debug logging
)

API Reference

Envelopes

# List envelopes
envelopes = client.envelopes.list(status="DRAFT")

# Get an envelope
envelope = client.envelopes.get("envelope_id")

# Create an envelope
envelope = client.envelopes.create(name="My Contract", message="Please sign")

# Add a recipient
recipient = client.envelopes.add_recipient(
    envelope_id="envelope_id",
    email="signer@example.com",
    name="John Doe",
    role="signer",
)

# Send for signing
envelope = client.envelopes.send("envelope_id")

# Void an envelope
envelope = client.envelopes.void("envelope_id", reason="Contract cancelled")

Documents

# Upload a document
with open("contract.pdf", "rb") as f:
    document = client.documents.upload(
        envelope_id="envelope_id",
        file=f.read(),
        filename="contract.pdf",
    )

# Get signed document URL
result = client.documents.get_signed_url("document_id")
print(result["url"])

# Download a document
content = client.documents.download("document_id")

Templates

# List templates
templates = client.templates.list()

# Create from template
envelope = client.templates.use(
    template_id="template_id",
    name="New Contract",
    recipients=[
        {"roleId": "role_1", "email": "signer@example.com", "name": "John Doe"}
    ],
)

Contacts

# List contacts
contacts = client.contacts.list(search="acme", limit=20)

# Create a contact
contact = client.contacts.create(
    email="contact@example.com",
    name="Jane Smith",
    company="Acme Inc",
)

Webhooks

# Create a webhook
webhook = client.webhooks.create(
    url="https://your-app.com/webhooks/authensure",
    events=["envelope.signed", "envelope.completed"],
)

# Verify webhook signature
from authensure.resources.webhooks import WebhooksResource

is_valid = WebhooksResource.verify_signature(
    payload=request_body,
    signature=request.headers["X-Authensure-Signature"],
    secret="your_webhook_secret",
)

# Construct verified event
event = WebhooksResource.construct_event(
    payload=request_body,
    signature=signature,
    secret="your_webhook_secret",
)
print(f"Event type: {event.event}")
print(f"Data: {event.data}")

Error Handling

from authensure import (
    Authensure,
    AuthensureError,
    AuthenticationError,
    ValidationError,
    NotFoundError,
    RateLimitError,
)

try:
    envelope = client.envelopes.get("invalid_id")
except NotFoundError:
    print("Envelope not found")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited, retry after: {e.retry_after} seconds")
except ValidationError as e:
    print(f"Validation errors: {e.validation_errors}")
except AuthensureError as e:
    print(f"API error: {e.message} (code: {e.code})")

Development

Install development dependencies

pip install -e ".[dev]"

Run tests

pytest

Run tests with coverage

pytest --cov=src/authensure --cov-report=html

Type checking

mypy src/authensure

Linting

ruff check src/authensure

Resources

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

authensure-1.0.1.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

authensure-1.0.1-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

Details for the file authensure-1.0.1.tar.gz.

File metadata

  • Download URL: authensure-1.0.1.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for authensure-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2d53d8a068296cd6f9b182f8a5d53884a20015d871d7604dcfc6c6762ee609d6
MD5 9f7393bf36231e1b0b747d4bbc2d0275
BLAKE2b-256 267322cd51fca422a86a9e45f37cc363d84722f24b0639e66167a85b15593546

See more details on using hashes here.

File details

Details for the file authensure-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: authensure-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 29.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for authensure-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e9b586ce94f8ac42daf20cee9e15f29bda3fe0684b6bca2bd1765ac4fd7143b9
MD5 8907ab01f12cab84658e5453e91a3833
BLAKE2b-256 5bec9ff5bc16de24b2ca7b8985c512208c5cf9d6a0c17d9ab64749f9a8d89544

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