A minimal Python SDK for the Openapi® API marketplace
Project description
openapi-python-sdk
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.
Requirements
- Python 3.10+
- An account on console.openapi.com with a valid API key
Installation
pip install openapi-python-sdk
Usage
Interaction with the Openapi platform happens in two distinct steps.
Step 1 — Generate a token
from openapi_python_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)
Step 2 — Call an API endpoint
from openapi_python_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"}},
)
Testing
pip install pytest
pytest
OauthClient API
| Method | Description |
|---|---|
OauthClient(username, apikey, test=False) |
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. |
Client API
| Method | Description |
|---|---|
Client(token) |
Initialize the client with a bearer token. |
request(method, url, payload, params) |
Execute an HTTP request against any Openapi endpoint. |
Links
- 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
License
MIT — see LICENSE for details.
Authors
- Michael Cuffaro (@maiku1008)
- Openapi Team (@openapi-it)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openapi_python_sdk-0.2.0.tar.gz.
File metadata
- Download URL: openapi_python_sdk-0.2.0.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.8.0-106-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
067a7b61fd4bec0456cb2d5fc4daa722dc44cad0bbaa64c5cd194327d1176342
|
|
| MD5 |
49d7a45a0bd64240d1db8a1e92f55490
|
|
| BLAKE2b-256 |
f6a9b5eaa81956ef95d8d8e1889dd0d99073f038ec3eb9419246f32688b1f841
|
File details
Details for the file openapi_python_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: openapi_python_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.8.0-106-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d96582563dddfa021bd7c00645b790ede39aee651a23bf0fb19267afd6c8e4f0
|
|
| MD5 |
ba84ee92dff6e8974e6f64b500402bc7
|
|
| BLAKE2b-256 |
ce608ee425a074eb7e9ebb93d58b128097f1f02e6557e9161a0c14dd5875bacb
|