Skip to main content

bytekit-sdk

Official Python SDK for the ByteKit API.

The PyPI distribution is bytekit-sdk; the import name is bytekit.

Generated from the OpenAPI spec using openapi-python-client, filtered to the stable v0.1 operations.

Installation

pip install bytekit-sdk

The installed version is available as bytekit.__version__.

Quick start

from bytekit import AuthenticatedClient
from bytekit.api.scrape import create_scrape
from bytekit.models.scrape_request import ScrapeRequest
from bytekit.models.scrape_request_formats_item import ScrapeRequestFormatsItem
from bytekit.models.scrape_success_envelope import ScrapeSuccessEnvelope

# base_url defaults to https://api.bytekit.com, so only the token is required.
client = AuthenticatedClient(token="sk_live_your_api_key_here")

result = create_scrape.sync(
    client=client,
    body=ScrapeRequest(
        url="https://example.com",
        # Ask for markdown explicitly. `formats` is a list of enum members, not plain
        # strings. Omit it and the server returns raw HTML instead, leaving
        # `formats.markdown` unset.
        formats=[ScrapeRequestFormatsItem.MARKDOWN],
    ),
)

if isinstance(result, ScrapeSuccessEnvelope):
    print(result.formats.markdown)

See Error handling for what result can be when the request fails.

Error handling

The SDK has a two-tier error contract. Both tiers are safe: an operation never raises a bare json.JSONDecodeError, even when a server returns an HTML error page.

Situation What you get
A status the OpenAPI spec documents for that operation (e.g. a 422 or 500 on create_scrape), with a JSON body The typed Error model is returned, not raised. Check with isinstance(result, Error) and read result.error.code / result.error.message.
An undocumented status, or a non-JSON body on a documented status (HTML error page, load-balancer text, empty body) errors.UnexpectedStatus is raised, carrying .status_code and the raw .content. When the body is the documented Error envelope, .code / .message are populated too.
Either of the above, with raise_on_unexpected_status=False Nothing is raised; the operation returns None.
from bytekit import AuthenticatedClient
from bytekit.api.scrape import create_scrape
from bytekit.errors import UnexpectedStatus
from bytekit.models.error import Error
from bytekit.models.scrape_request import ScrapeRequest
from bytekit.models.scrape_success_envelope import ScrapeSuccessEnvelope

client = AuthenticatedClient(token="sk_live_your_api_key_here")

try:
    result = create_scrape.sync(client=client, body=ScrapeRequest(url="https://example.com"))
except UnexpectedStatus as err:
    # Undocumented status, or a non-JSON body on a documented one. Never a JSONDecodeError.
    print(f"request failed with status {err.status_code}: {err.code} {err.message}")
else:
    if isinstance(result, Error):
        # Documented 4xx/5xx with a JSON body: RETURNED as a typed model, not raised.
        print(f"api error {result.error.code}: {result.error.message}")
    elif isinstance(result, ScrapeSuccessEnvelope):
        print(result.formats.markdown)
    else:
        # 202 ScrapeQueuedEnvelope — poll get_scrape with this id until it completes.
        print(f"queued as {result.id}")

Defaults

The client ships with production-ready defaults so AuthenticatedClient(token=...) works out of the box:

Setting Default Notes
base_url https://api.bytekit.com Pass base_url= to target staging or a proxy.
timeout 120s (httpx.Timeout(120.0)) Finite by default — requests no longer hang indefinitely. Pass timeout= to override.
raise_on_unexpected_status True Undocumented statuses raise errors.UnexpectedStatus instead of silently returning None. Pass raise_on_unexpected_status=False to restore the old opt-out.

Explicit constructor arguments always win over these defaults (explicit arg > default).

Async usage

import asyncio
from bytekit import AuthenticatedClient
from bytekit.api.screenshots import create_screenshot
from bytekit.models.screenshot_request import ScreenshotRequest

async def main():
    client = AuthenticatedClient(token="sk_live_your_api_key_here")
    body = ScreenshotRequest(url="https://example.com")
    response = await create_screenshot.asyncio(client=client, body=body)
    print(response)

asyncio.run(main())

Clients and event loops

An httpx.AsyncClient — and therefore its connection pool — belongs to the event loop that created it. The recommended shape is a context manager, which scopes the client to exactly one loop:

async def main():
    async with AuthenticatedClient(token="sk_live_your_api_key_here") as client:
        ...

Two rules cover everything else:

  • A client the SDK builds for you is rebuilt automatically. If you reuse one client across several asyncio.run(...) calls, the SDK notices the running loop has changed and transparently replaces its internal AsyncClient. Your base_url, headers, timeout, httpx_args and authentication are all re-applied, so this is invisible apart from a new connection. Calling get_async_httpx_client() outside any running loop returns the cached client unchanged.
  • A client you pass to set_async_httpx_client(...) is yours. The SDK never rebuilds or closes it, so a client you supply must be created and used on the same loop — that is the one case where crossing loops is still your responsibility.

Available operations

Module Method Description
api.scrape create_scrape, get_scrape Web content extraction
api.screenshots create_screenshot, get_screenshot Page screenshots
api.bulk create_bulk, get_bulk, delete_bulk, list_bulk_screenshots Bulk screenshot jobs
api.scrape_bulk create_scrape_bulk, get_scrape_bulk Bulk scrape jobs
api.fetch get_fetch, post_fetch Raw HTTP fetch
api.fetch_bulk create_fetch_bulk, get_fetch_bulk Bulk fetch jobs
api.monitors create_monitor, list_monitors, get_monitor, update_monitor, delete_monitor, list_monitor_captures Page-change monitors (screenshot + scrape)
api.sitemap create_sitemap, get_sitemap Sitemap crawl
api.search create_search (or the AuthenticatedClient.search(...) convenience method) Web search
api.usage get_usage, get_usage_daily, get_usage_by_endpoint Account usage & billing
api.webhooks list_webhook_deliveries, retry_webhook_delivery Webhook delivery log & retry
api.account get_account Account details

License

MIT — see LICENSE.

Release files for bytekit-sdk 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bytekit-sdk 0.3.4
File Size Uploaded
bytekit_sdk-0.3.4.tar.gz 96.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bytekit-sdk 0.3.4
File Interpreter ABI Platform
bytekit_sdk-0.3.4-py3-none-any.whl Python 3 none any Details

Total release size: 318.5 kB

Release files / bytekit_sdk-0.3.4.tar.gz

Download URL bytekit_sdk-0.3.4.tar.gz
Size 96.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ae2cc92da8648cd4ab4f6bb617ff88ed882871d6ec3276a82d2930f03c2a5608
BLAKE2b-256 checksum
How to use checksums
d4ce031a2c70a9b9b8dda869b114400dd7cae418b3f6cd74a8f7deb946a7cc5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / bytekit_sdk-0.3.4-py3-none-any.whl

Download URL bytekit_sdk-0.3.4-py3-none-any.whl
Size 222.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcd752637aff036da2791326649d576128f9466507095c8dd629c9c61deb1551
BLAKE2b-256 checksum
How to use checksums
7ae46a0b96a2e6a6523a0ed5175f70bbd8a11dc4b02c6a86d72c79afae475ee7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

0.9.0

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.6

2 release files

0.3.5

2 release files

This release

0.3.4 This release

2 release files

0.3.2

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page