Metadata-Version: 2.4
Name: pypaligo
Version: 0.1.0
Summary: A Python API wrapper for the Paligo REST API v2
Project-URL: Homepage, https://github.com/sam-purgavie/pypaligo
Project-URL: Repository, https://github.com/sam-purgavie/pypaligo
Project-URL: Issues, https://github.com/sam-purgavie/pypaligo/issues
Author: Sam P (Spury)
License: MIT License
        
        Copyright (c) 2026 Sam P (Spury)
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: api,docs-as-code,documentation,paligo,wrapper
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: requests>=2.28
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: responses>=0.23; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Description-Content-Type: text/markdown

# pypaligo

A Python wrapper for the [Paligo](https://paligo.net/) 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

```bash
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).

```python
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:

```python
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:

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

## Usage

Methods return plain `dict`s and `list`s parsed straight from the API JSON.

```python
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:

```python
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:

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

Once retries are exhausted, a `PaligoRateLimitError` is raised.

## Development

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

## License

MIT — see [LICENSE](LICENSE).
