Skip to main content

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

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

License

MIT — see LICENSE for details.

Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openapi_python_sdk-0.2.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openapi_python_sdk-0.2.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

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

Hashes for openapi_python_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 067a7b61fd4bec0456cb2d5fc4daa722dc44cad0bbaa64c5cd194327d1176342
MD5 49d7a45a0bd64240d1db8a1e92f55490
BLAKE2b-256 f6a9b5eaa81956ef95d8d8e1889dd0d99073f038ec3eb9419246f32688b1f841

See more details on using hashes here.

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

Hashes for openapi_python_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d96582563dddfa021bd7c00645b790ede39aee651a23bf0fb19267afd6c8e4f0
MD5 ba84ee92dff6e8974e6f64b500402bc7
BLAKE2b-256 ce608ee425a074eb7e9ebb93d58b128097f1f02e6557e9161a0c14dd5875bacb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page