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

Uploaded Python 3

File details

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

File metadata

  • Download URL: intelliprint_py-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 c65ccc08aa87fbddda6ea66422015e768365b820347a880a5eff5b3e86bfe6bf
MD5 9ad09f935586493bce79ca69e080ea2a
BLAKE2b-256 0fe7e86b5c470fdc078f823d054e9d718f405238a6a39a5a3fec99ea7b1b283f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: intelliprint_py-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 864840faae3099d7bc1dace841bf154ba990d55e2c2a89ae6a465991501ad7fd
MD5 79016f6bfb4d488d9bfac0a320ef7615
BLAKE2b-256 5844d18d2642eb4a897b8fbd7ecd97ccc7724131d8f035ee66a19eb81f39649a

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