Skip to main content

Unofficial Python SDK for the Intelliprint API - Send physical mail as easily as sending email

Project description

intelliprint-py

Unofficial Python SDK for the Intelliprint API - Send physical mail as easily as sending email.

PyPI version Python versions License: MIT

Installation

pip install intelliprint-py

Quick Start

from intelliprint_py import (
    IntelliprintClient,
    IntelliprintAddress,
    IntelliprintRecipient,
)

# Initialize the client
client = IntelliprintClient(api_key="your-api-key")
# Or use environment variable: INTELLIPRINT_API_KEY

# Create a simple print job
print_job = client.prints.create(
    content="<h1>Hello World!</h1><p>This is my first letter.</p>",
    testmode=True,  # Required: explicitly set test mode
    recipients=[
        IntelliprintRecipient(
            address=IntelliprintAddress(
                name="John Doe",
                line="123 Main Street, London",
                postcode="SW1A 1AA",
            )
        )
    ],
)

print(f"Created print job: {print_job['id']}")

Using UserData

For more structured recipient management, use the UserData model:

from intelliprint_py import (
    IntelliprintClient,
    UserData,
    UserAddress,
)

client = IntelliprintClient(api_key="your-api-key")

# Create user data with extra fields for template variables
user = UserData(
    first_name="John",
    last_name="Doe",
    email="john@example.com",
    user_id="customer_12345",
    address=[
        UserAddress(
            building_number="123",
            thoroughfare="Main Street",
            post_town="London",
            postcode="SW1A 1AA",
        )
    ],
    extra={
        "membership_level": "gold",
        "account_balance": "£150.00",
    },
)

# Create a print job using user data
print_job = client.prints.create(
    content="""
    <h1>Welcome, {first_name}!</h1>
    <p>Your membership level: {membership_level}</p>
    <p>Current balance: {account_balance}</p>
    """,
    testmode=True,
    user_data=user,
)

Services

Prints

Create and manage print jobs (letters and postcards):

# Create a print job
print_job = client.prints.create(
    content="Hello World!",
    testmode=True,
    recipients=[...],
)

# Get a print job
print_job = client.prints.get("print_xxx")

# List print jobs
jobs = client.prints.list(limit=10, testmode=True)

# Update a print job
client.prints.update("print_xxx", reference="Updated reference")

# Confirm a print job for printing
client.prints.confirm("print_xxx")

# Delete/cancel a print job
client.prints.delete("print_xxx")

Backgrounds

Manage letterhead backgrounds (no user data required):

# Create a background
with open("letterhead.pdf", "rb") as f:
    background = client.backgrounds.create(
        file_content=f.read(),
        file_name="letterhead.pdf",
        name="Company Letterhead",
    )

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

# Use a background in a print job
print_job = client.prints.create(
    content="Hello!",
    testmode=True,
    recipients=[...],
    background=BackgroundSettings(
        first_page="bg_xxx",
        other_pages="bg_yyy",
    ),
)

Mailing Lists

Manage mailing lists and recipients:

# Create a mailing list
mailing_list = client.mailing_lists.create(name="Newsletter Subscribers")

# Add a user to the mailing list
client.mailing_lists.add_user(
    mailing_list_id="mal_xxx",
    user_data=user,
    additional_variables={"signup_date": "2024-01-15"},
)

# List recipients
recipients = client.mailing_lists.list_recipients("mal_xxx")

# Send to a mailing list
print_job = client.prints.create(
    template="tmpl_xxx",
    testmode=True,
    mailing_list="mal_xxx",
)

Configuration Options

Print Settings

from intelliprint_py import (
    PrintingSettings,
    PostageSettings,
    PostageService,
    EnvelopeSize,
)

print_job = client.prints.create(
    content="Important document",
    testmode=True,
    recipients=[...],
    printing=PrintingSettings(
        double_sided="yes",
        premium_quality=True,
        black_and_white=False,
    ),
    postage=PostageSettings(
        service=PostageService.UK_FIRST_CLASS,
        ideal_envelope=EnvelopeSize.C4,
    ),
)

Error Handling

from intelliprint_py import IntelliprintClient, IntelliprintError

client = IntelliprintClient(api_key="your-api-key")

try:
    print_job = client.prints.get("invalid_id")
except IntelliprintError as e:
    print(f"Error: {e.message}")
    print(f"Type: {e.error_type}")
    print(f"Code: {e.error_code}")

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
ruff check src/

# Run type checking
mypy src/

License

MIT License - see LICENSE for details.

Links

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

intelliprint_py-0.1.1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

intelliprint_py-0.1.1-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file intelliprint_py-0.1.1.tar.gz.

File metadata

  • Download URL: intelliprint_py-0.1.1.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for intelliprint_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 985a5d077ed45461b0d922d4a5c34f5b7e07c94b127c4798be5dd0c98450ea73
MD5 d9faf24fe7feed5cec1107ceab3fc906
BLAKE2b-256 f42c73e9c10f5159ee4997b86587e135ba61a2419224c9eea0e29875c961b215

See more details on using hashes here.

File details

Details for the file intelliprint_py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: intelliprint_py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for intelliprint_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 005060d92bc92b540236ab0a1a165cc052a30ffedfbde3773c50f212980520e7
MD5 357583be88fbae2644642ff5abfc44e0
BLAKE2b-256 d7c7e2207d3bcfc1bbea38e3f74fe6bdd2b848eb1881598b3908e654d3d82a30

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