Skip to main content

Python client for the Subnoto Public API

Project description

Subnoto Python SDK

Python client for the Subnoto Public API.

Table of contents

Installation

Requirements: Python 3.9+

Install from PyPI:

pip install subnoto-api-client

Usage

The SDK provides both async and sync clients. Use SubnotoClient for async/await code or SubnotoSyncClient for synchronous code. Credentials are required; you can pass them explicitly or set SUBNOTO_ACCESS_KEY and SUBNOTO_SECRET_KEY.

Async Example

import asyncio
from subnoto_api_client import SubnotoClient, SubnotoConfig

async def main():
    async with SubnotoClient(SubnotoConfig()) as client:
        response = await client.post("/public/workspace/list", json={})
        print(f"Workspaces: {response.json()}")

if __name__ == "__main__":
    asyncio.run(main())

Sync Example

from subnoto_api_client import SubnotoSyncClient, SubnotoConfig

with SubnotoSyncClient(SubnotoConfig()) as client:
    response = client.post("/public/workspace/list", json={})
    print(f"Workspaces: {response.json()}")

Configuration

Option Type Required Description
access_key str Yes API access key (or set env var SUBNOTO_ACCESS_KEY)
secret_key str Yes API secret key, hex-encoded (or set env var SUBNOTO_SECRET_KEY)

Error handling and tunnel retry

The SDK follows the Subnoto error reference. On tunnel 401 errors (TUNNEL_SESSION_NOT_FOUND or TUNNEL_ERROR), the client automatically invalidates the tunnel session and retries the request up to 3 times with a new session. You do not need to manage tunnel lifecycle when using SubnotoClient or SubnotoSyncClient.

For custom handling you can use the exported helpers and codes. You can raise SubnotoError(message, response.status_code) with the response body message and status code.

from subnoto_api_client import (
    SubnotoClient,
    SubnotoConfig,
    get_error_code,
    is_tunnel_error,
    SubnotoError,
    TUNNEL_SESSION_NOT_FOUND,
    TUNNEL_ERROR,
)

async def main():
    async with SubnotoClient(SubnotoConfig()) as client:
        response = await client.post("/public/utils/whoami", json={})
        if response.status_code != 200:
            body = response.json()
            code = get_error_code(body)  # works with API shape (error.code) and top-level code
            if is_tunnel_error(body):
                # SDK already retried (up to 3 times); this is the result after retries
                pass
            msg = body.get("error", {}).get("message", str(body)) if isinstance(body, dict) else str(body)
            raise SubnotoError(msg, response.status_code)

See the Subnoto error reference for all error codes.

Documentation

The API documentation is available here.

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

subnoto_api_client-2.16.0-cp311-abi3-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.11+Windows x86-64

subnoto_api_client-2.16.0-cp311-abi3-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file subnoto_api_client-2.16.0-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for subnoto_api_client-2.16.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ed97991325e16f7ecf551e389763e1e5db5c49ee05c553006bab9cc6886fa9fa
MD5 491d8dddadf5b0dcea95e84aac1b9f02
BLAKE2b-256 f491d57fd1a7dac6d51bc9ccb58853201d98f5de1bcceddc9981f12674080b5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for subnoto_api_client-2.16.0-cp311-abi3-win_amd64.whl:

Publisher: .gitlab-ci.yml on subnoto/subnoto-monorepo-public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subnoto_api_client-2.16.0-cp311-abi3-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for subnoto_api_client-2.16.0-cp311-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 950e83c181058cd44a2caf3ea4abb7ab28567ea21661a0a4eec37fe9a8099098
MD5 6d4c8310e61f0d2180c8b7c9d0bec49d
BLAKE2b-256 d3040e95a8f3b43c6f4a1d0601f35dd2467da795653322025ac8a0c7b8f26237

See more details on using hashes here.

Provenance

The following attestation bundles were made for subnoto_api_client-2.16.0-cp311-abi3-manylinux2014_x86_64.whl:

Publisher: .gitlab-ci.yml on subnoto/subnoto-monorepo-public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subnoto_api_client-2.16.0-cp311-abi3-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for subnoto_api_client-2.16.0-cp311-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0969c48cc23a7b5d84b701ea32fe62a1302d531b32a58d1a33e64fe5183cc356
MD5 51eeaacfe60d491b735252454e5438e2
BLAKE2b-256 d2616e150c4bdb05cf2ddb383e46b25ea546cd3583894f58249a5c6808848f09

See more details on using hashes here.

Provenance

The following attestation bundles were made for subnoto_api_client-2.16.0-cp311-abi3-manylinux2014_aarch64.whl:

Publisher: .gitlab-ci.yml on subnoto/subnoto-monorepo-public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subnoto_api_client-2.16.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for subnoto_api_client-2.16.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 24774007f4d35cc0b1569c41902ec7cfcbf036a0a058cc2b0ed0a20e450b1a3b
MD5 10cee62f3415a437e20a968ca60ea4a9
BLAKE2b-256 52f8334180e3432c34ea8cc13c08f046b265fe0b702e728f5fc37d72b76bd670

See more details on using hashes here.

Provenance

The following attestation bundles were made for subnoto_api_client-2.16.0-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: .gitlab-ci.yml on subnoto/subnoto-monorepo-public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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