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

Uploaded CPython 3.11+Windows x86-64

subnoto_api_client-2.13.4-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.13.4-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for subnoto_api_client-2.13.4-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7af6a67a108f13dc527c06b5bbaaf97fbbd69be67d1809d2b0a72082998ec51f
MD5 c8bf3bc0f4c4c2b031e154507eacb022
BLAKE2b-256 a2881f6552db5f98a3705ef65434738ca24f8d477f4420f56b7253cd6b9e16bd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subnoto_api_client-2.13.4-cp311-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 505c6e815d57a83111a67fd0efc402f8d8d264fcb7a13155f0756e58d3f51bac
MD5 f4a8a1e9b7c8b0cd5f891e8c2d534b8c
BLAKE2b-256 354da7832d87b45f03cb345f0076fe17d560d42d5b66d5e9d32ad2d5265a461a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subnoto_api_client-2.13.4-cp311-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 152b8c7b8343a9c9709bbd924987e01cf75806ce163c12f2676cc697511e0fe9
MD5 f1555cf642058d68b14d3e0037dafb23
BLAKE2b-256 ae4e6805206c69e26fd2d8c61af231790260c995769ecf8281e3236c041d632b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subnoto_api_client-2.13.4-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 008e3f9f963b2eec28584b2a6510f043e71c20c10e50a4a46874204c2c4ed2e5
MD5 a3e9bc8614665f92be1d06d23f929357
BLAKE2b-256 d960c1a3fa11644929f411c9491ac7f4c2f9561b14152517f10882263a6b3000

See more details on using hashes here.

Provenance

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