Skip to main content

Typed Core

Shared core types and utilities for Typed Clients

PyPI version License

Every Typed Client builds its core on top of this package. Prefer it over a client-local copy of the same logic — a client's own core/ should hold only what's genuinely venue-specific (envelope extraction, error mapping, signing, wire quirks), not a reimplementation of transport, timestamps, or error types.

Installation

pip install typed-core

What it provides

module contents
typed_core.exceptions Error, NetworkError, ValidationError, ApiError (BadRequest, AuthError, RateLimited), LogicError
typed_core.http async HTTP client and response helpers
typed_core.ws websocket socket, streams, JSON-RPC, streams-over-RPC
typed_core.times TimeConverter, EpochConverter, IsoConverter — parse/dump between a venue's wire timestamp and a real datetime
typed_core.util RateLimit, paging and stream helpers
from typed_core.times import EpochConverter, IsoConverter

timestamp_millis = EpochConverter.milliseconds()  # epoch, milliseconds
timestamp_iso = IsoConverter()                    # RFC 3339, Z-suffixed

A wire value carrying no offset is read as UTC, matching what dump already assumes of a naive datetime; pass tz=None to keep it naive instead. Every converter raises ValueError on a value of the wrong kind, so a null on a non-nullable field arrives as an ordinary validation error rather than an AttributeError.

HTTP configuration

from typed_core.http import HttpClient

async with HttpClient(timeout=30, proxy="http://localhost:8080") as http:
  response = await http.request("GET", "https://example.com")
  response = await http.request("GET", "https://example.com", timeout=120)

timeout defaults to five seconds of network inactivity; None disables timeouts. Use httpx.Timeout for separate connect, read, write, and pool limits. Per-request timeout overrides the client default. Requests are single-attempt, with retries left to the caller.

proxy accepts a URL or an httpx.Proxy, including authenticated proxies. When omitted, HTTPX uses HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, and NO_PROXY from the environment. An explicit proxy overrides environment proxy routing, including NO_PROXY. For an HTTPS destination, an http:// proxy URL commonly works by tunneling the TLS connection. trust_env=False ignores HTTPX environment settings (proxies and certificate locations), but still uses an explicit proxy. See HTTPX environment variables.

limits continues to control connection pooling. The existing default disables keepalive when uppercase HTTP_PROXY or HTTPS_PROXY is present; pass explicit httpx.Limits to override it, including when using trust_env=False.

All construction settings apply when the underlying HTTPX client is lazily created. An existing client supplied through the legacy _client field keeps its own configuration. A Typed client accepting http=... manages that transport's cleanup when its context exits; use separate transports for independently managed client lifetimes.

Paging

Every generated <method>_paged returns a PaginatedResponse: awaitable (every row, flattened) and async-iterable (one page of rows at a time). Each page is one pure next(state) call, so a caller can retry or resume a single page rather than the whole walk.

from typed_core import PaginatedResponse

paging = client.market.kline_paged(symbol='BTCUSDT', interval='1', start=start, end=end)
candles = await paging                       # every row, flattened
async for rows in paging: ...                # one page at a time
async for page in paging.pages():            # Page(rows, state, next), for checkpointing
  checkpoint(page.next)
paging.resume(saved_state)                   # restart from a checkpointed state
paging.via(retried)                          # route every page fetch through a middleware

via(call) hands each page fetch to call as one zero-argument coroutine function, so a retry or logging layer wraps a page without unrolling the loop by hand.

WebSocket connection drops

Streams and requests are bound to the connection they were made on. When it drops, or the client is closed, everything bound to it raises NetworkError:

  • a stream raises right away if it is being iterated, otherwise on its next read (after any message it had already received); it never reconnects on its own
  • a request waiting for its reply raises

Leaving a stream whose connection is gone (async with exit or unsubscribe()) does nothing: no frame, no reconnect, no exception, so the stream's own NetworkError is what surfaces. A new subscription or request after a drop simply opens a fresh connection. Resubscribing is up to the caller:

from typed_core.exceptions import NetworkError

while True:
  try:
    async with socket.subscribe('trades') as trades:
      async for trade in trades:
        ...
  except NetworkError:
    await asyncio.sleep(1)  # then subscribe again, on a fresh connection

Clients re-export the exceptions users are expected to catch from their own package root, so from kraken import AuthError works while implementation imports still come from typed_core. Route those re-exports through lazy_loader.attach_stub, not a plain from typed_core.exceptions import ... in an __init__.py — the latter breaks type-checking for every downstream consumer of a py.typed package.

License

MIT — see LICENSE.

Release files for typed-core 0.9.1

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

Source distribution (sdist)

Source distribution for typed-core 0.9.1
File Size Uploaded
typed_core-0.9.1.tar.gz 43.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for typed-core 0.9.1
File Interpreter ABI Platform
typed_core-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 76.0 kB

Release files / typed_core-0.9.1.tar.gz

Download URL typed_core-0.9.1.tar.gz
Size 43.0 kB
Tags Source
SHA-256 checksum
How to use checksums
45e538666b08707693b281fdbfa7a9d234ac2861417481fc109c3dac3df6962b
BLAKE2b-256 checksum
How to use checksums
fe1030c4ce2b62a2aa3eca4a56ce5619051b3f7a73f7090e0718c8013e535f85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / typed_core-0.9.1-py3-none-any.whl

Download URL typed_core-0.9.1-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62a8ffe1302ef0a65fbe5d8c99e728316c73d9a0e822ffcdbb8fb7a9c05a86d7
BLAKE2b-256 checksum
How to use checksums
14f72f3577e56ad4a41ae51468a3a2f9428b56a1904233ac9ab5fded3285f4a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

0.9.2

2 release files

This release

0.9.1 This release

2 release files

0.9.0

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.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.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