Skip to main content

Unofficial Python client for the Presscart API.

Project description

pypresscart — A Python Library for the Presscart API

CI Docs PyPI Python License: MIT Ruff Checked with mypy Types - Pydantic pre-commit

📚 Documentation · PyPI · Issues

⚠️ Unofficial library. This project is not affiliated with, endorsed by, or supported by Presscart. It's a community-maintained Python client for the Presscart API.

  • Pythonic, typed resource methods (client.outlets.list(...), client.orders.create_checkout(...), ...)
  • Dual-mode: pass Pydantic models or plain dicts; get Pydantic models or plain dicts back
  • Single dependency stack — requests + pydantic
  • Built-in exponential-backoff retry for 429 / 5xx responses, honoring Retry-After
  • Typed exception hierarchy (BadRequestError, AuthenticationError, RateLimitError, ...)

Install

uv add pypresscart
# or
pip install pypresscart

Python 3.10+.

Quickstart

from pypresscart import PresscartClient

client = PresscartClient(api_token="pc_...")

me = client.auth.whoami()
print(me.team_id, me.scopes)

outlets = client.outlets.list(limit=5, filters={"country": "United States"})
for row in outlets.records:
    print(row.outlet_name, row.website_url)

Dual-mode usage

The library accepts both Pydantic models and raw dicts on the way in, and returns either on the way out.

from pypresscart import CheckoutLineItem, CheckoutRequest, PresscartClient

client = PresscartClient(api_token="pc_...")

# Pydantic in, Pydantic out (default)
order = client.orders.create_checkout(
    CheckoutRequest(
        profile_id="YOUR_PROFILE_ID",
        line_items=[CheckoutLineItem(product_id="YOUR_PRODUCT_ID", quantity=1)],
    )
)
print(order.reference_number)

# Dict in, dict out
raw = client.orders.create_checkout(
    {
        "profile_id": "YOUR_PROFILE_ID",
        "line_items": [
            {"product_id": "YOUR_PRODUCT_ID", "quantity": 1, "is_add_on": False}
        ],
        "discount": 0,
    },
    as_json=True,
)
print(raw["reference_number"])

You can also set the default for the whole client:

client = PresscartClient(api_token="pc_...", response_mode="json")

Per-call as_json=True / as_json=False always wins over the client default.

Error handling

from pypresscart import (
    AuthenticationError,
    NotFoundError,
    PresscartAPIError,
    RateLimitError,
    ValidationError,
)

try:
    client.campaigns.get("missing")
except NotFoundError as exc:
    print("not found:", exc.message)
except AuthenticationError:
    print("token invalid or expired")
except RateLimitError as exc:
    print("slow down; retry after", exc.retry_after)
except ValidationError as exc:
    for issue in exc.issues:
        print("field", issue["path"], issue["message"])
except PresscartAPIError as exc:
    print(exc.status_code, exc.name, exc.message, exc.payload)

All API errors inherit from PresscartAPIError. Network-level failures raise PresscartTransportError (wrapping the underlying requests exception).

Client options

Parameter Default Description
api_token (required) Bearer token (pc_...)
base_url https://api.presscart.com API origin
timeout 30.0 Per-request timeout (seconds)
max_retries 3 Additional attempts on 429/5xx/network errors
retry_backoff_base 0.25 Base backoff seconds
retry_backoff_max 4.0 Backoff cap
retry_jitter 0.1 Fractional jitter
response_mode "pydantic" "pydantic" or "json"
user_agent "pypresscart/<version>" User-Agent header
session None Inject a pre-configured requests.Session

Use as a context manager to close the session automatically:

with PresscartClient(api_token="pc_...") as client:
    ...

Endpoints

Every endpoint documented at docs.presscart.com is covered by a method on one of the resource services:

Service Methods
client.auth whoami
client.outlets list, get, list_products, list_countries, list_states, list_cities, list_tags, list_disclaimers
client.products get, list_listings, list_categories
client.orders list, get, create_checkout
client.order_items list
client.profiles list_team_profiles, list_orders, list_order_items, list_campaigns
client.campaigns list, get, create, update, list_articles, article_status_counts, assign_order_items, link_questionnaire
client.articles get, update, approve_brief, approve_draft
client.files list, get, upload, download, move, delete
client.folders list, create, rename, delete

Each method's docstring includes the required token scope.

Documentation

Full documentation lives at https://annjawn.github.io/py-presscart/ — Sphinx site built from docs/ and deployed automatically by .github/workflows/docs.yml on every push to main.

Build locally:

uv sync --group docs
uv run sphinx-build -b html -n -W --keep-going docs docs/_build/html
open docs/_build/html/index.html

# Or with live reload:
uv run sphinx-autobuild docs docs/_build/html --watch src/pypresscart

Development

uv sync --group dev
uv run pytest -v
uv run ruff check .
uv run ruff format --check .
uv run mypy src
uv build

Pre-commit hooks

This repo ships a .pre-commit-config.yaml with ruff, mypy, whitespace/EOL/yaml/toml checks, and a pytest hook on pre-push.

uv run pre-commit install                      # ruff + mypy on every commit
uv run pre-commit install --hook-type pre-push # pytest on every push
uv run pre-commit run --all-files              # run everything now

License

MIT — see LICENSE.

Presscart™ and the Presscart logo are trademarks of their respective owners. This library is an independent, unofficial client.

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

pypresscart-0.1.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

pypresscart-0.1.0-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file pypresscart-0.1.0.tar.gz.

File metadata

  • Download URL: pypresscart-0.1.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypresscart-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5aec4dcd3d2af73e2a9357441bdc68c207508e7ff7d3c42934c27c73a04aa9c7
MD5 7d08c2a50b2feebf9b020cf1ec60b019
BLAKE2b-256 1a10ed637bb8551116e3020e5dcf31ab556a6f02bbc9f17c267831fd45b70947

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypresscart-0.1.0.tar.gz:

Publisher: release.yml on annjawn/py-presscart

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypresscart-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pypresscart-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypresscart-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19f90512c7cc98baa5aedc2ab883f8412518ed4842940ca8996f91b4a317f4ab
MD5 a0346c8ebb451add29b14b82a70dff2c
BLAKE2b-256 30b7522453a5a0e7510363c56e1287fd509a0c340b5677b1aafe7435cc0046b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypresscart-0.1.0-py3-none-any.whl:

Publisher: release.yml on annjawn/py-presscart

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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