Skip to main content

A Python API wrapper for the Paligo REST API v2

Project description

pypaligo

A Python wrapper for the Paligo REST API v2.

pypaligo gives you a small, typed, synchronous client over the Paligo API. Every documented v2 endpoint is covered, grouped into resource namespaces (client.documents, client.variables, client.imports, …). Non-2xx responses raise typed exceptions, and rate-limit (429) responses are retried automatically using the server's Retry-After header.

Installation

pip install pypaligo

Requires Python 3.10+.

Authentication

The Paligo API uses HTTP Basic auth with your Paligo username and API key (the user must be an admin). Each Paligo customer has their own subdomain, so you must supply your instance name (or a full base URL).

from pypaligo import PaligoClient

# instance name -> https://mycompany.paligoapp.com/api/v2/
client = PaligoClient("mycompany", username="me@example.com", api_key="APIKEY")

Credentials also fall back to the PALIGO_USERNAME and PALIGO_API_KEY environment variables:

import os
os.environ["PALIGO_USERNAME"] = "me@example.com"
os.environ["PALIGO_API_KEY"] = "APIKEY"

client = PaligoClient("mycompany")

The client is a context manager and closes its HTTP session on exit:

with PaligoClient("mycompany") as client:
    doc = client.documents.get(1234)

Usage

Methods return plain dicts and lists parsed straight from the API JSON.

from pypaligo import PaligoClient
from pypaligo.resources.documents import STATUS_RELEASED

with PaligoClient("mycompany") as client:
    # Documents
    doc = client.documents.get(1234)
    client.documents.update(1234, name="New title")
    client.documents.set_release_status(1234, STATUS_RELEASED)
    client.documents.add_taxonomies(1234, [55, 66])   # merges with existing

    # List one page, or iterate every page
    first_page = client.documents.list(parent=10, per_page=50)
    for d in client.documents.iter(parent=10):
        print(d["id"], d["name"])

    # Search
    doc_id = client.search.find_by_uuid("UUID-b4d615c4-...")
    results = client.search.query(
        "documents",
        where=[client.search.where_equals("name", "Release notes")],
    )

    # Variables
    for variable in client.variables.iter(variable_set_id=7):
        print(variable["title"])
    client.variable_values.update(999, value="new text value")

    # Imports (multipart upload)
    imp = client.imports.create("content.zip", parent=10, type="xhtml")

    # Productions & outputs
    prod = client.productions.create("publishsetting.1234-5678")
    client.outputs.download("output-name.zip", "out.zip")

Resource namespaces

Namespace Endpoints
client.documents list / iter / get / create / update / delete, plus set_release_status, add_taxonomies
client.folders list / iter / get / create
client.forks list / iter / get / create / delete
client.images list / iter / get / create / update (multipart)
client.search query, find_by_uuid, where_* clause builders
client.imports list / get / create (multipart)
client.outputs get (bytes) / download (to file)
client.productions list / get / create
client.publish_settings list / iter / get
client.translation_exports list / get / create
client.translation_imports list / get / create (multipart)
client.taxonomies list / iter / get / create / update / delete
client.variable_sets list / iter / get / create / update / delete
client.variants list / iter / get / create / update / delete
client.variables list / iter / get / create / update / delete
client.variable_values list / iter / get / create / update
client.groups list / iter / get
client.assignments list / iter / get / create / update / delete
client.users list / iter / get

Error handling

All errors derive from PaligoError. Non-2xx responses raise PaligoAPIError (carrying .status_code, .body, and the underlying .response), with more specific subclasses for common cases:

from pypaligo import (
    PaligoAPIError,
    PaligoAuthError,       # 401 / 403
    PaligoNotFoundError,   # 404
    PaligoRateLimitError,  # 429 after retries are exhausted (has .retry_after)
    PaligoConnectionError, # network-level failure, no HTTP response
)

try:
    client.documents.get(999999)
except PaligoNotFoundError:
    print("no such document")
except PaligoAPIError as exc:
    print(exc.status_code, exc.body)

Rate limiting

The client retries 429 responses automatically (default: 3 retries), honouring the server's Retry-After header and falling back to a 60-second backoff when the header is absent. Configure the retry count per client:

client = PaligoClient("mycompany", max_retries=5)

Once retries are exhausted, a PaligoRateLimitError is raised.

Development

pip install -e ".[dev]"
ruff check .
pytest

License

MIT — see LICENSE.

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

pypaligo-0.1.1.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

pypaligo-0.1.1-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pypaligo-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a94d184cdd617b3db43a2ff03fb2156e02188ad885de0c17122d2434765cd512
MD5 36699986e4585fa2631f0637e4ec3798
BLAKE2b-256 5cdd26b4d40c7503c786771d86537368e18f7f58e1197151c8c5610e277c6d81

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pypaligo-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a22d2bc73aec50d4d03c50794d20f58533a1cc1ac5dc0569c9ee49e3a46b0612
MD5 60bfa395df431bbe98431383e8d5cdac
BLAKE2b-256 3c23db9032ce62d247e7dfdad5c122db09fce360691902ae544f347fa629f029

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