Skip to main content

Official Python SDK for the Parcel Wing API.

Project description

Parcel Wing Python SDK

The official Python SDK for the Parcel Wing API.

It is designed for a fast, predictable developer experience:

  • resource clients for emails, contacts, segments, topics, and automations
  • consistent ParcelWingError exceptions
  • typed package metadata and exported type hints
  • small dependency surface built on httpx
  • works with the same public API contract used by Parcel Wing itself

Installation

pip install parcelwing

Quick start

First you'll need an API key. If you don't have one, sign up and create one at https://parcelwing.com/signup. It's free, with no credit card required.

import os

from parcelwing import ParcelWing

parcel_wing = ParcelWing(api_key=os.environ["PARCEL_WING_API_KEY"])

emails = parcel_wing.emails.send(
    from_="Acme <hello@yourdomain.com>",
    to="person@example.com",
    subject="Hello from Parcel Wing",
    text="It works.",
)

print(emails[0]["id"])

from is a Python keyword, so the keyword-argument API uses from_. You can also pass a raw API dictionary if you prefer exact API field names:

emails = parcel_wing.emails.send({
    "from": "Acme <hello@yourdomain.com>",
    "to": "person@example.com",
    "subject": "Hello from Parcel Wing",
    "text": "It works.",
})

Using templates

emails = parcel_wing.emails.send(
    from_="Acme <hello@yourdomain.com>",
    to="person@example.com",
    template_alias="welcome_email",
    template_params={
        "first_name": "John",
    },
)

Contacts

contact = parcel_wing.contacts.create({
    "email": "person@example.com",
    "first_name": "John",
    "attributes": {
        "plan": "pro",
    },
})

page = parcel_wing.contacts.list(page=1, limit=20)

print(len(page["data"]), page.get("pagination", {}).get("total"))

Batch create contacts:

result = parcel_wing.contacts.create([
    {"email": "one@example.com", "first_name": "One"},
    {"email": "two@example.com", "first_name": "Two"},
])

print(result["created"])
print(result["failed"])

Segments

segment = parcel_wing.segments.create({
    "name": "Pro plan users",
    "filter_criteria": {
        "version": 1,
        "match": "all",
        "conditions": [
            {
                "field": "attribute",
                "attribute_key": "plan",
                "operator": "equals",
                "value": "pro",
            },
        ],
    },
})

Topics

topic = parcel_wing.topics.create({
    "name": "Product Updates",
    "description": "Feature launches and release notes.",
    "default_subscription": "opt_in",
    "visibility": "public",
})

Automation events

parcel_wing.automations.track({
    "event_name": "user.completed_onboarding",
    "contact_id": "6d9dc8f7-c44e-4f2d-8a4e-d04f32f1744f",
    "payload": {
        "plan": "flight",
    },
})

Error handling

from parcelwing import ParcelWingError

try:
    parcel_wing.emails.send(
        from_="Acme <hello@yourdomain.com>",
        to="person@example.com",
        subject="Hello",
        text="Hi there",
    )
except ParcelWingError as error:
    print(error.status, error.type, error.code, error.request_id)
    print(error.details)

Configuration

parcel_wing = ParcelWing(
    api_key=os.environ["PARCEL_WING_API_KEY"],
    base_url="https://parcelwing.com",
    timeout=30.0,
)

Use the client as a context manager to close the underlying HTTP connection pool automatically:

with ParcelWing(api_key=os.environ["PARCEL_WING_API_KEY"]) as parcel_wing:
    emails = parcel_wing.emails.send(
        from_="Acme <hello@yourdomain.com>",
        to="person@example.com",
        subject="Hello",
        text="It works.",
    )

Local development

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest
ruff check .
mypy src/parcelwing

Publishing

python -m pip install build twine
python -m build
twine upload dist/*

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

parcelwing-0.1.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

parcelwing-0.1.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: parcelwing-0.1.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for parcelwing-0.1.1.tar.gz
Algorithm Hash digest
SHA256 939f89924296d419e9a7a0871172bfc99f66f432d211c00030cc9a1523b54a8d
MD5 0a3dead7f1d8646d12b92a8daf32cf7e
BLAKE2b-256 cc6ffefadbbac5b40db1a5316e5633137e3658e0e201cf77299226f72f99f984

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parcelwing-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for parcelwing-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b0360c4ef4531a6c01f2cfc7703c5de526ae6e255eae99e1d97d0afa465b7bbc
MD5 8193f52f4389032d9a010976e3a50116
BLAKE2b-256 1f02e8a53fb65f6c2b3f18ed975a1f2c97c19ea8e52b59a37ee28bdd71e286f1

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