Skip to main content

tketool.core

tketool.core contains the shared configuration, file, cache, command, in-memory async messaging, and utility APIs used by the other tketool distributions.

pip install tketool.core
from tketool.core import ConfigManager, read_file, write_file
from tketool.core.cache.sqlite import init_db

Optional dependencies are grouped by feature:

pip install "tketool.core[storage]"
pip install "tketool.core[documents]"
pip install "tketool.core[console]"

In-memory async messaging

tketool.core.messaging provides a small replaceable publish/subscribe contract and a dependency-free in-memory adapter:

import asyncio

from tketool.core.messaging import create_message_bus


async def main() -> None:
    bus = create_message_bus()

    async def handle_order(message) -> None:
        print(message.message_id, message.payload)

    subscription = await bus.subscribe(
        "orders.created",
        handle_order,
        max_queue_size=100,
        handler_timeout=5.0,
    )

    receipt = await bus.publish("orders.created", {"order_id": "o-1"})
    assert receipt.subscriber_count == 1
    await bus.wait_idle()

    await subscription.close()
    await bus.close()


asyncio.run(main())

One subscription processes messages serially in FIFO order; different subscriptions run concurrently. A successful publish only confirms that the message was accepted by the subscriber queues. Handler failures are available through Subscription.last_error and an optional on_error callback.

This adapter is process-local and bound to one asyncio event loop. It does not persist messages, share work across processes, retry failures, or provide exactly-once delivery. Mutable payloads are passed by reference and should be treated as read-only. Use a durable broker adapter for work that must survive a restart.

Lifecycle and error handling

Use the bus as an async context manager when its lifetime matches one application scope:

import asyncio

from tketool.core.messaging import HandlerError, create_message_bus


async def report_error(error: HandlerError) -> None:
    print(error.message.message_id, error.exception)


async def process_document(message) -> None:
    print(message.payload["document_id"])


async def main() -> None:
    async with create_message_bus() as bus:
        await bus.subscribe(
            "documents.ready",
            process_document,
            handler_timeout=10.0,
            on_error=report_error,
        )
        await bus.publish("documents.ready", {"document_id": "d-1"})
        await bus.wait_idle()


asyncio.run(main())

publish() waits only for subscriber queues to accept the message. It returns a PublishReceipt; callback completion is observed with wait_idle(). Exceptions and async callback timeouts increment Subscription.failed_count, set Subscription.last_error, and invoke on_error. They are not sent back to the publisher and are not retried automatically.

close(drain=True) stops accepting new work and finishes accepted messages. close(drain=False) drops queued messages and cancels subscription workers. Synchronous callbacks are supported, but run on the event-loop thread and must not block; explicitly use asyncio.to_thread for blocking functions.

Delivery model

Property In-memory adapter behavior
Routing Exact topic match
Multiple subscribers Fan-out: every active subscriber receives the message
Ordering FIFO within one subscription
Concurrency Serial within one subscription; concurrent across subscriptions
Backpressure Bounded per-subscriber queues; publish() waits when full
Handler failure Recorded and isolated; no automatic retry
Persistence/replay None
Thread/process support One asyncio event loop in one process

If several workers should compete for one message instead of all receiving it, that is a work-queue/competing-consumer contract and is intentionally separate from this publish/subscribe API.

Verification and design documents

bash scripts/test-package.sh core

Metadata

Release files for tketool.core 2.0.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 tketool.core 2.0.1
File Size Uploaded Provenance Actions
tketool_core-2.0.1.tar.gz 109.4 kB Without provenance Details for tketool_core-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tketool.core 2.0.1
File Interpreter ABI Platform Actions
tketool_core-2.0.1-py3-none-any.whl Python 3 none any Details for tketool_core-2.0.1-py3-none-any.whl

Total release size: 232.1 kB

Release files / tketool_core-2.0.1.tar.gz

Download URL tketool_core-2.0.1.tar.gz
Size 109.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bbbfd1e8a46b9880abbf09ec6d70b16fc1eb575ea07319fa07b3e9a99fdf403b
BLAKE2b-256 checksum
How to use checksums
ae4ccc3cf62212c9ceafe253a826145d02f94dadca833d561b9a28b9dbc04494
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / tketool_core-2.0.1-py3-none-any.whl

Download URL tketool_core-2.0.1-py3-none-any.whl
Size 122.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61822b4300e64021d8f7580b03b5ce8a86f0e9e3bae70df6a2a3b6fc3bf147cd
BLAKE2b-256 checksum
How to use checksums
6dcb0a8dd777c07257a4a982151d8817d270e7d9146156f5c014cb9d2c84eee6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for tketool.core 2.0.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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