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.15.1-cp311-abi3-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.11+Windows x86-64

subnoto_api_client-2.15.1-cp311-abi3-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for subnoto_api_client-2.15.1-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3f7edb2fbf3a396da110366f8b39992e009b455f34f8ba711b968e7beab90b39
MD5 687ae537200c9d950c38cb0af2ddd3c9
BLAKE2b-256 b5f416f5958d64103b4e02108ff29267fea7adf5b70ff0f7cf1ecf861554926a

See more details on using hashes here.

Provenance

The following attestation bundles were made for subnoto_api_client-2.15.1-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.15.1-cp311-abi3-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for subnoto_api_client-2.15.1-cp311-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 360ba19b0324f5cfee31e1a3be1ab56060aa84ff06e21481f3b27462f9b11336
MD5 63634802934896780818f8ff82fa695d
BLAKE2b-256 bf2b8e946a7de1f162da33155427965af2be2d8273c972dddcb7140a30c9f352

See more details on using hashes here.

Provenance

The following attestation bundles were made for subnoto_api_client-2.15.1-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.15.1-cp311-abi3-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for subnoto_api_client-2.15.1-cp311-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 41e02530d9b5951b5051e7d46e9bb605de2d7beff5bf8c032ad5287f9cfd2b0e
MD5 d7f0741c10f1c7600c7f1a78df2fd62c
BLAKE2b-256 6fb6a0da905f1e6465837d6cc02970519e6c133fdf9b1e14124aa953488a63e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for subnoto_api_client-2.15.1-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.15.1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for subnoto_api_client-2.15.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d1c1aec368a9ea9039998498e1c2718cca2e23f6c20ed5e31d740081db30a5e4
MD5 2c00e2938663a4935b8d409a567b8a36
BLAKE2b-256 e15b34b9af4d8baa8ca8c7125a6b00816d7bda651ab38cb6942fb295c44d3e15

See more details on using hashes here.

Provenance

The following attestation bundles were made for subnoto_api_client-2.15.1-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