A minimal Python SDK for Openapi® — the largest certified API marketplace in Italy. Provides the core HTTP primitives to authenticate and interact with any Openapi service, without API-specific coupling.
- Python 3.10+
- An account on console.openapi.com with a valid API key
pip install openapi-sdkInteraction with the Openapi platform happens in two distinct steps.
from openapi_sdk.client import OauthClient
oauth = OauthClient(username="<your_username>", apikey="<your_apikey>", test=True)
resp = oauth.create_token(
scopes=[
"GET:test.imprese.openapi.it/advance",
"POST:test.postontarget.com/fields/country",
],
ttl=3600,
)
token = resp["token"]
# Revoke the token when done
oauth.delete_token(id=token)from openapi_sdk.client import Client
client = Client(token=token)
# GET with query params
resp = client.request(
method="GET",
url="https://test.imprese.openapi.it/advance",
params={"denominazione": "altravia", "provincia": "RM", "codice_ateco": "6201"},
)
# POST with a JSON payload
resp = client.request(
method="POST",
url="https://test.postontarget.com/fields/country",
payload={"limit": 0, "query": {"country_code": "IT"}},
)By default, the SDK uses a 30-second timeout for all network requests. You can easily override it passing a timeout explicitly during initialization:
from openapi_sdk.client import Client
client = Client(token="token", timeout=60.0) # 60 secondspip install pytest
pytest| Method | Description |
|---|---|
OauthClient(username, apikey, test=False, timeout=30.0) |
Initialize the OAuth client. Set test=True for sandbox. |
create_token(scopes, ttl) |
Create a bearer token for the given scopes and TTL (seconds). |
get_token(scope) |
Retrieve an existing token by scope. |
delete_token(id) |
Revoke a token by ID. |
get_scopes(limit=False) |
List available scopes. |
get_counters(period, date) |
Retrieve usage counters for a given period and date. |
| Method | Description |
|---|---|
Client(token, timeout=30.0) |
Initialize the client with a bearer token. |
request(method, url, payload, params) |
Execute an HTTP request against any Openapi endpoint. |
- Homepage: openapi.it
- Console & API keys: console.openapi.com
- GitHub: github.com/openapi/openapi-python-sdk
- Issue tracker: github.com/openapi/openapi-python-sdk/issues
MIT — see LICENSE for details.
- Michael Cuffaro (@maiku1008)
- Openapi Team (@openapi-it)