Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ installed `onepin` is **below that floor**, the SDK stops with a clear, copy-pas
onepin 0.4.1 is below the required minimum 0.5.0. Upgrade: pip install --upgrade 'onepin>=0.5.0'
```

The `onepin` CLI enforces this automatically. For **programmatic** use, build the client with
`onepin.make_client` (instead of `OnePinClient` directly) to get the same gate plus a corrected
`User-Agent`:
The `onepin` CLI enforces this automatically. For **programmatic** use, `OnepinClient` has the
same gate built in plus a corrected `User-Agent` (`make_client` is the explicit-token equivalent
if you are not using credential resolution):

```python
import onepin

client = onepin.make_client(token="op_live_...")
client = onepin.OnepinClient() # resolves your key (arg / ONEPIN_API_KEY / `onepin login`), version-gated
client.workflows.list() # raises onepin.OnePinUpgradeRequiredError if the SDK is too old
```

Expand Down Expand Up @@ -440,9 +440,9 @@ Full per-endpoint reference: [`src/onepin/reference.md`](src/onepin/reference.md
hosted docs at [onepin.ai/docs](https://onepin.ai/docs). Runnable scripts in [`examples/`](examples/).

```python
from onepin import OnePinClient
from onepin import OnepinClient

client = OnePinClient(token="op_...") # your API key, used as the bearer token
client = OnepinClient(api_key="op_...") # or set ONEPIN_API_KEY, or run `onepin login`

workflows = client.workflows.list() # paginated — iterate items directly
voices = client.voices.list()
Expand All @@ -451,22 +451,19 @@ voices = client.voices.list()
### Environments

```python
from onepin import OnePinClient
from onepin.environment import OnePinClientEnvironment
from onepin import OnepinClient

# Defaults to PROD (https://api.onepin.ai). Target the dev API instead:
client = OnePinClient(token="op_...", environment=OnePinClientEnvironment.DEV)
# ...or point at any host directly:
client = OnePinClient(token="op_...", base_url="https://dev-api.onepin.ai")
# Defaults to PROD (https://api.onepin.ai). Target the dev API by URL:
client = OnepinClient(api_key="op_...", base_url="https://dev-api.onepin.ai")
```

### Async

```python
import asyncio
from onepin import AsyncOnePinClient
from onepin import AsyncOnepinClient

client = AsyncOnePinClient(token="op_...")
client = AsyncOnepinClient(api_key="op_...")


async def main() -> None:
Expand All @@ -479,10 +476,10 @@ asyncio.run(main())
### Errors, retries, timeouts

```python
from onepin import OnePinClient
from onepin import OnepinClient
from onepin.core.api_error import ApiError

client = OnePinClient(token="op_...", timeout=20.0) # client-wide timeout (default 60s)
client = OnepinClient(api_key="op_...", timeout=20.0) # client-wide timeout (default 60s)

try:
client.workflows.get(
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ python examples/quickstart.py
|------|-------|
| `quickstart.py` | Construct a client, list workflows |
| `list_workflows.py` | Paginate workflows, fetch one by id |
| `async_client.py` | `AsyncOnePinClient` + async pagination |
| `async_client.py` | `AsyncOnepinClient` + async pagination |
| `error_handling.py` | `ApiError`, retries, timeouts |

By default the client targets **PROD** (`https://api.onepin.ai`). Pass
`environment=OnePinClientEnvironment.DEV` or `base_url="https://dev-api.onepin.ai"` to
`base_url="https://dev-api.onepin.ai"` to
target another host. See the repo [README](../README.md#sdk-usage) and the full
per-endpoint reference in [`src/onepin/reference.md`](../src/onepin/reference.md).
6 changes: 3 additions & 3 deletions examples/async_client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Async client usage with the AsyncOnePinClient."""
"""Async client usage with the AsyncOnepinClient."""

import asyncio
import os

from onepin import AsyncOnePinClient
from onepin import AsyncOnepinClient


async def main() -> None:
client = AsyncOnePinClient(token=os.environ["ONEPIN_API_KEY"])
client = AsyncOnepinClient(api_key=os.environ["ONEPIN_API_KEY"])

# AsyncPager is async-iterable.
voices = await client.voices.list()
Expand Down
4 changes: 2 additions & 2 deletions examples/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import os

from onepin import OnePinClient
from onepin import OnepinClient
from onepin.core.api_error import ApiError


def main() -> None:
client = OnePinClient(token=os.environ["ONEPIN_API_KEY"], timeout=20.0)
client = OnepinClient(api_key=os.environ["ONEPIN_API_KEY"], timeout=20.0)

try:
client.workflows.get(
Expand Down
4 changes: 2 additions & 2 deletions examples/list_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import os

from onepin import OnePinClient
from onepin import OnepinClient


def main() -> None:
client = OnePinClient(token=os.environ["ONEPIN_API_KEY"])
client = OnepinClient(api_key=os.environ["ONEPIN_API_KEY"])

# `list()` returns a SyncPager — iterate items directly, or use `.iter_pages()`.
for index, workflow in enumerate(client.workflows.list()):
Expand Down
4 changes: 2 additions & 2 deletions examples/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import os

from onepin import OnePinClient
from onepin import OnepinClient


def main() -> None:
client = OnePinClient(token=os.environ["ONEPIN_API_KEY"])
client = OnepinClient(api_key=os.environ["ONEPIN_API_KEY"])

# Workflows in your workspace. `list()` returns a pager you can iterate directly.
for workflow in client.workflows.list():
Expand Down
4 changes: 2 additions & 2 deletions fern/generators.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fern generator config for the OnePin Python SDK.
# Fern generator config for the Onepin Python SDK.
#
# This repo self-generates its SDK. The OnePin API spec is shaped upstream (x-fern + servers
# This repo self-generates its SDK. The Onepin API spec is shaped upstream (x-fern + servers
# folded into the published OpenAPI), so this is a VANILLA generate — no overlay/overrides here.
#
# regen.yml fetches the shaped spec into ./openapi/openapi.yml, then `fern generate
Expand Down
6 changes: 3 additions & 3 deletions scripts/post_fern.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Post-process Fern output after it overwrites src/onepin/:
# 1. Restore py.typed PEP 561 markers.
# 2. Rebrand the generated SDK README ("Podonos" -> "OnePin").
# 2. Rebrand the generated SDK README ("Podonos" -> "Onepin").
# Run this after every `fern generate` invocation.
set -euo pipefail
touch src/onepin/py.typed
Expand All @@ -10,8 +10,8 @@ echo "Restored py.typed markers after Fern regen."

# Brand name only: case-sensitive so the lowercase "podonos" org slug in URLs is preserved.
if [ -f src/onepin/README.md ]; then
sed -i.bak 's/Podonos/OnePin/g' src/onepin/README.md && rm -f src/onepin/README.md.bak
echo "Rebranded src/onepin/README.md (Podonos -> OnePin)."
sed -i.bak 's/Podonos/Onepin/g' src/onepin/README.md && rm -f src/onepin/README.md.bak
echo "Rebranded src/onepin/README.md (Podonos -> Onepin)."
fi

# Scrub an internal backend symbol path Fern copies verbatim from the spec docstring.
Expand Down
4 changes: 2 additions & 2 deletions src/onepin/_version_gate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Client-side SDK version gate (hand-written; preserved across ``fern generate`` via ``.fernignore``).

The Onepin API advertises the minimum SDK version it still accepts via the
``X-OnePin-Required-Version`` response header (and enforces it with HTTP 426). This module reads
``X-Onepin-Required-Version`` response header (and enforces it with HTTP 426). This module reads
that header off every response and stops the caller when the installed ``onepin`` package is
older than the floor.

Expand Down Expand Up @@ -31,7 +31,7 @@
from onepin.client import AsyncOnePinClient, OnePinClient

#: Response header the API uses to advertise the minimum acceptable SDK version.
REQUIRED_VERSION_HEADER = "X-OnePin-Required-Version"
REQUIRED_VERSION_HEADER = "X-Onepin-Required-Version"

_BASE_UPGRADE_COMMAND = "pip install --upgrade onepin"

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_version_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_unparseable_is_not_older(self) -> None:

class TestRequiredVersionFrom:
def test_case_insensitive(self) -> None:
assert vg.required_version_from({"X-OnePin-Required-Version": "0.7.0"}) == "0.7.0"
assert vg.required_version_from({"X-Onepin-Required-Version": "0.7.0"}) == "0.7.0"
assert vg.required_version_from({"x-onepin-required-version": "0.7.0"}) == "0.7.0"

def test_missing_and_blank(self) -> None:
Expand Down
Loading