Skip to main content

Speakeasy API Client SDK for Python

Project description

speakeasy-client-sdk-python

SDK Installation

pip install speakeasy-client-sdk-python

SDK Example Usage

import speakeasy
from speakeasy.models import operations, shared

s = speakeasy.Speakeasy(
    security=shared.Security(
        api_key="",
    ),
)

req = operations.GetApisRequest(
    metadata={
        "key": [
            'string',
        ],
    },
    op=operations.QueryParamOp(
        and_=False,
    ),
)

res = s.apis.get_apis(req)

if res.classes is not None:
    # handle response
    pass

Available Resources and Operations

Speakeasy SDK

apis

api_endpoints

metadata

schemas

requests

plugins

embeds

Pagination

Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the returned response object will have a Next method that can be called to pull down the next group of results. If the return value of Next is None, then there are no more pages to be fetched.

Here's an example of one such pagination call:

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an error. If Error objects are specified in your OpenAPI Spec, the SDK will raise the appropriate Error type.

Error Object Status Code Content Type
errors.SDKError 400-600 /

Example

import speakeasy
from speakeasy.models import shared

s = speakeasy.Speakeasy(
    security=shared.Security(
        api_key="",
    ),
)


res = None
try:
    res = s.validate_api_key()

except (errors.SDKError) as e:
    print(e) # handle exception


if res.status_code == 200:
    # handle response
    pass

Server Selection

Select Server by Name

You can override the default server globally by passing a server name to the server: str optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:

Name Server Variables
prod https://api.prod.speakeasyapi.dev None

For example:

import speakeasy
from speakeasy.models import shared

s = speakeasy.Speakeasy(
    server="prod",
    security=shared.Security(
        api_key="",
    ),
)


res = s.validate_api_key()

if res.status_code == 200:
    # handle response
    pass

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:

import speakeasy
from speakeasy.models import shared

s = speakeasy.Speakeasy(
    server_url="https://api.prod.speakeasyapi.dev",
    security=shared.Security(
        api_key="",
    ),
)


res = s.validate_api_key()

if res.status_code == 200:
    # handle response
    pass

Custom HTTP Client

The Python SDK makes API calls using the (requests)[https://pypi.org/project/requests/] HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom requests.Session object.

For example, you could specify a header for every request that this sdk makes as follows:

import speakeasy
import requests

http_client = requests.Session()
http_client.headers.update({'x-custom-header': 'someValue'})
s = speakeasy.Speakeasy(client: http_client)

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
api_key apiKey API key

You can set the security parameters through the security optional parameter when initializing the SDK client instance. For example:

import speakeasy
from speakeasy.models import shared

s = speakeasy.Speakeasy(
    security=shared.Security(
        api_key="",
    ),
)


res = s.validate_api_key()

if res.status_code == 200:
    # handle response
    pass

SDK Generated by Speakeasy

Project details


Release history Release notifications | RSS feed

This version

3.1.0

Download files

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

Source Distribution

speakeasy-client-sdk-python-3.1.0.tar.gz (28.5 kB view hashes)

Uploaded Source

Built Distribution

Supported by

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