Skip to main content

Truewire Core

Runtime for Truewire-generated API clients

PyPI version License

Every client generated by Truewire depends on this package. It holds the parts of a client that are the same for every API — async HTTP and WebSocket transport, response validation, paging, timestamp conversion and the error hierarchy — so that generated code only has to carry what is genuinely specific to one API: envelope extraction, error mapping, request signing, wire quirks.

You do not normally install it directly; a generated client lists it as a dependency. You will import from it when catching errors, converting timestamps, or driving a paginated walk.

Installation

pip install truewire-core

Optional extras:

pip install 'truewire-core[grpc]'   # gRPC transport (grpclib)

What it provides

module contents
truewire_core.exceptions Error, NetworkError, ValidationError, ApiError (BadRequest, AuthError, RateLimited), LogicError
truewire_core.http HttpClient, an async HTTP client wrapping httpx with lazy connection, NetworkError mapping, an explicit proxy=, pacing (rate=) and bounded retry (retry=)
truewire_core.ws WebSocket base classes: Socket, Streams, Rpc, StreamsRpc, SerialReplies; each takes proxy=
truewire_core.grpc GrpcClient, GrpcEndpoint, wrap_exceptions (requires the grpc extra)
truewire_core.validation validator[T], a cached pydantic adapter that validates and dumps wire shapes, and a base TypedDict that tolerates undocumented fields
truewire_core.times TimeConverter, EpochConverter, IsoConverter, DateConverter — parse/dump between a wire timestamp and a real datetime/date
truewire_core.types TimestampSeconds, TimestampMillis, TimestampMicros, TimestampNanos, TimestampIso, DateIso — the one alias per spec format that generated code imports, plus the converter instance behind each; TimestampSecondsFloat and the other ...Float twins for a type: number epoch; wire_row, the __get_pydantic_core_schema__ of a generated NamedTuple row, so it dumps its JSON array on pydantic before 2.14
truewire_core.contract HttpEndpoint, CommandEndpoint, StreamEndpoint, ClientRoot, Composite — Protocols spelling out what a hand-written core provides to generated code
truewire_core.util PaginatedResponse/Page, Stream/StreamManager, RateLimit, and small numeric/path helpers

Errors

Every failure a client raises derives from truewire_core.exceptions.Error:

from truewire_core.exceptions import ApiError, AuthError, NetworkError, RateLimited

try:
  order = await client.orders.get(id='ord_123')
except AuthError:
  ...          # bad or missing credentials
except RateLimited:
  ...          # the API told us to slow down
except ApiError as e:
  ...          # any other error the API itself returned (BadRequest, ...)
except NetworkError:
  ...          # couldn't reach the server, or the connection dropped

Generated clients re-export these from their own package root, so from my_client import AuthError works too. Route such re-exports through lazy_loader.attach_stub (with a matching __init__.pyi), not a plain from truewire_core.exceptions import ... in an __init__.py — the latter breaks type-checking for every downstream consumer of a py.typed package.

Timestamps

APIs put timestamps on the wire in many shapes: epoch seconds, milliseconds, microseconds or nanoseconds; RFC 3339 strings with or without a Z; plain calendar dates. Each converter turns one such shape into a real datetime (or date) and back:

from datetime import timezone
from truewire_core.times import DateConverter, EpochConverter, IsoConverter

timestamp_millis = EpochConverter.milliseconds(tz=timezone.utc)   # 1717072496123 <-> datetime
timestamp_seconds = EpochConverter.seconds(tz=timezone.utc)       # 1717072496 <-> datetime
timestamp_iso = IsoConverter()                                    # '2024-05-30T12:34:56Z' <-> datetime
calendar_date = DateConverter()                                   # '2024-05-30' <-> date

dt = timestamp_iso.parse('2024-05-30T12:34:56.123456789Z')       # any fraction length, any Python >= 3.10
timestamp_millis.dump(dt)                                         # 1717072496123

A generated client wires these into its field types through pydantic, so a response field declared as a millisecond epoch arrives as a datetime and a request parameter typed as one is serialized back to the wire format the API expects.

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 truewire_core import PaginatedResponse

paging = client.orders.list_paged(status='open')
orders = 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.

Validation

Generated response types are TypedDicts. validator wraps a cached pydantic TypeAdapter around one and raises truewire_core.exceptions.ValidationError (not pydantic's own) when the wire body doesn't match:

from truewire_core.validation import TypedDict, validator

class Order(TypedDict):
  id: str
  amount: str

order = validator(Order)(b'{"id": "ord_123", "amount": "10.5", "extra": true}')
# {'id': 'ord_123', 'amount': '10.5', 'extra': True} -- undocumented fields are kept, not rejected
validator(Order).dump(order)   # b'{"id":"ord_123","amount":"10.5","extra":true}'

License

MIT — see LICENSE.

Metadata

Release files for truewire-core 0.3.2

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

Source distribution (sdist)

Source distribution for truewire-core 0.3.2
File Size Uploaded
truewire_core-0.3.2.tar.gz 67.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for truewire-core 0.3.2
File Interpreter ABI Platform
truewire_core-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 111.5 kB

Release files / truewire_core-0.3.2.tar.gz

Download URL truewire_core-0.3.2.tar.gz
Size 67.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ebea109fc4ae6e4d16ae976da3c54bbace75c9780e111629ece6b48bdf78d08f
BLAKE2b-256 checksum
How to use checksums
3a21e45e110868a401745f78ef1be3ed1d2199fbf51838bd4f47e4f50d616afe
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 Oct 14, 2026.

Transparency log

Release files / truewire_core-0.3.2-py3-none-any.whl

Download URL truewire_core-0.3.2-py3-none-any.whl
Size 44.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c466218e752f7347dca7c1608d8637bdd7bb991bc49a4265e758589ceb9eb38d
BLAKE2b-256 checksum
How to use checksums
b9417167dcf818b44e4691fa7b0543ba1f21ace660025b56296ea84bf238e2b7
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 Oct 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

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