> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ocpplab.com/llms.txt.
> For full documentation content, see https://docs.ocpplab.com/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ocpplab.com/_mcp/server.

# Python SDK

The `ocpplab` Python SDK wraps the OCPPLAB Gateway REST API with typed models and both sync and async clients. Source lives in [`ocpplab-sdk/sdks/python`](https://github.com/ocpplab/ocpplab-sdk/tree/main/sdks/python).

## Install

```bash
pip install ocpplab
```

## Initialize

```python
from ocpplab import OcpplabSDK

client = OcpplabSDK(
    token="<access-token>",
    base_url="https://<your-api-host>",
)
```

`token` maps to `Authorization: Bearer <token>`. User tokens are all you need — see [Authentication](/authentication) for the admin case.

## Provision a single charger

```python
client.chargers.create(
    identity="CP-BAY-01",
    brand_slug="alfen",
    model_slug="alfen_eve_double_pg_line_de",
    connector_type="Type2",
    ws_url="wss://ocpp.ocpplab.com",
    ocpp_version="OCPP1.6",
    charge_point_name="Bay 01",
    location_id=location.id,
    location_name="Bare Hub 01",
)
```

## Bulk-provision from a template

```python
from ocpplab import ChargerGroup, ChargerTemplate

client.location_chargers.create(
    location_id=location.id,
    request=[
        ChargerGroup(
            template=ChargerTemplate(
                brand_slug="alfen",
                model_slug="alfen_eve_double_pg_line_de",
                connector_type="Type2",
                ocpp_version="OCPP1.6",
                ws_url="wss://ocpp.ocpplab.com",
                identity_prefix="SITE_01_",
                template_name="Bay",
            ),
            charger_ids=["001", "002"],
        )
    ],
)
```

## Spin up a CPO bundle

```python
cpo = client.ocpi_cpos.create(
    template="small-urban-ac",
    country_code="FR",
    party_id="DEM",
    name_prefix="demo",
)
```

## Async client

```python
import asyncio
from ocpplab import AsyncOcpplabSDK

client = AsyncOcpplabSDK(
    token="<access-token>",
    base_url="https://<your-api-host>",
)

async def main() -> None:
    await client.ocpi_cpos.create(
        template="small-urban-ac",
        country_code="FR",
        party_id="DEM",
        name_prefix="demo",
    )

asyncio.run(main())
```

## Error handling

```python
from ocpplab.core.api_error import ApiError

try:
    client.chargers.create(...)
except ApiError as e:
    print(e.status_code, e.body)
```

## Retries and timeouts

The SDK retries on `408`, `429`, and `5xx` with exponential backoff (default: 2 attempts). Default timeout is 60 seconds.

```python
client = OcpplabSDK(..., timeout=20.0)

client.chargers.create(
    ...,
    request_options={"max_retries": 1, "timeout_in_seconds": 10},
)
```

## Next step

Continue to [Quickstart](/quickstart) for the end-to-end onboarding flow, or [Common workflows](/common-workflows) for bulk provisioning and OCPI bundles.