Metadata-Version: 2.5
Name: nojuf07djs
Version: 0.1.0
Summary: Python SDK for the Demo API
Project-URL: Repository, https://github.com/lonely-school-vibes/nojuf07djs/tree/HEAD/sdk-python
Project-URL: Issues, https://github.com/lonely-school-vibes/nojuf07djs/issues
Keywords: api,client,nojuf07djs,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Framework :: Pydantic :: 2
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx2<3,>=2
Requires-Dist: pydantic<3,>=2.11
Requires-Dist: typing-extensions>=4.5
Description-Content-Type: text/markdown

# Demo Python SDK

[![PyPI](https://img.shields.io/pypi/v/nojuf07djs)](https://pypi.org/project/nojuf07djs/)

This package calls the Demo API from Python, with a synchronous and an asynchronous client built on `httpx2`. It includes Pydantic models for every request and reply.

[Issues](https://github.com/lonely-school-vibes/nojuf07djs/issues)

## Installation

Install the SDK from PyPI. It needs Python 3.10 or later.

```sh
uv add nojuf07djs
```

<details>
<summary>Other package managers</summary>

```sh
pip install nojuf07djs
```

```sh
poetry add nojuf07djs
```

```sh
pdm add nojuf07djs
```

</details>

## Usage

Call the API:

```python
from nojuf07djs import Demo

demo = Demo()
data = demo.ping.get()
print(data)
```

The same call with `AsyncDemo`:

```python
import asyncio

from nojuf07djs import AsyncDemo

async_demo = AsyncDemo()


async def main() -> None:
    data = await async_demo.ping.get()
    print(data)


asyncio.run(main())
```

## Closing the client

The client opens a connection pool on its first call, and a `with` block closes it on the way out. A client that lives as long as the process closes with `close()` when you shut down. A client you passed as `http_client` is yours to close.

```python
from nojuf07djs import Demo

with Demo() as demo:
    demo.ping.get()
```

The same with `AsyncDemo`, which closes with `aclose()`:

```python
import asyncio

from nojuf07djs import AsyncDemo


async def main() -> None:
    async with AsyncDemo() as async_demo:
        await async_demo.ping.get()


asyncio.run(main())
```

## Errors

When the API answers with an error status, the call raises `APIError`, or a subclass named for the status. Every exception the SDK raises subclasses `DemoError`, except `pydantic.ValidationError` for an argument its model refuses, which is raised before anything is sent.

```python
from nojuf07djs import APIError, Demo

demo = Demo()
try:
    demo.ping.get()
except APIError as error:
    print(error.status, error.body)
```

## Retries

A failed call is sent again up to 2 times, after a lost connection, a 408, 425 or 429 status, or most 5xx statuses. Each wait is longer than the last on average, or as long as `Retry-After` asks. Set `max_retries` on the client or on one call:

```python
from nojuf07djs import Demo

demo = Demo(max_retries=5)
demo.with_options(max_retries=0).ping.get()
```

## Timeouts

Each attempt may run for 60 seconds. One that runs longer raises `TransportTimeoutError`. Set `timeout` in seconds on the client or on one call, or `False` for no limit:

```python
from nojuf07djs import Demo

demo = Demo(timeout=20)
demo.with_options(timeout=5).ping.get()
```

## Logging

To see what the SDK sends and receives, set `log_level` or the `DEMO_LOG` environment variable. `"info"` logs each call and its reply, and `"debug"` adds headers, with credentials redacted. Logging is off until you do. Records go to a logger under `nojuf07djs`, which writes to standard error until the application configures logging. Pass `logger` to use your own.

```python
from nojuf07djs import Demo

demo = Demo(log_level="info")
```

## Custom HTTP client

To send requests over HTTP/2, through a proxy, or with other TLS settings or connection limits, pass an `httpx2.Client` you built as `http_client`. HTTP/2 needs the `httpx2[http2]` extra. `AsyncDemo` takes an `httpx2.AsyncClient`.

```python
import httpx2

from nojuf07djs import Demo

demo = Demo(http_client=httpx2.Client(http2=True))
```

## Requirements

- Python 3.10 or later
