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

Uploaded CPython 3.11+Windows x86-64

subnoto_api_client-2.12.6-cp311-abi3-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for subnoto_api_client-2.12.6-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f86de4338c7dc6ebaf727526f22985c48fe5a695f86318eeaf84181dc883b1ee
MD5 26b2374bb32b240814a1b74d910948f3
BLAKE2b-256 fc4c061ca611761539f7f219457fd856a04b77c18e0012f291728a1a8fb1e8d6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subnoto_api_client-2.12.6-cp311-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d198bfd1bf010de5d0e355f78e631c0bba5d8609601d4b531e6cca0452a1d15d
MD5 bbcba2dcf26c09b65e81069f496c2bdb
BLAKE2b-256 23b12f4d93e9d9ac2d598e6a9440a116df6ce13f4744224c53136b3b958980cf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subnoto_api_client-2.12.6-cp311-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 41917b67617691c16e78688688c91ea057eb9a8a969c0d2aae33530198bfa919
MD5 76d20b1e1ecd312916bb41c951611dc7
BLAKE2b-256 8e1cbe066d0165a6a68ffff6586e41a58603b83fb8cfe1a17196709ad6486f63

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subnoto_api_client-2.12.6-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b333326ac47c813cd6bc324d07da3e6a74eb4fc2807fe4a7d5ecea977c05b5e
MD5 31c4003bbf97c4c158f0bae8288b85a2
BLAKE2b-256 0652617e6b84d9ba89c06ca8ac26c2ff76553e8ecc5fe6d7f2ecd2f88d888f44

See more details on using hashes here.

Provenance

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