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.0.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.0-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: authensure-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 b388721bb60d3d33a3e69fafae17900936b1a4e79c996ab741c4f861e0e3cf50
MD5 109fb256019301fef2862e9c34b4a94f
BLAKE2b-256 34a5a8642b58de08bb710890841378543286125a3ab4abd232d8c88fbbdd57f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: authensure-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8653de8d86c0ff87a052bd087c09ce7695b2639d1f7cce3d19672638318f7aa
MD5 78aa9c9d8c4635d97f822078b397badb
BLAKE2b-256 2f011d4c3a3f214475eee3b6a8f0feaf8e2abece600cada4b997c8981a303b9f

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