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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tketool_core-1.3.5.tar.gz (107.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tketool_core-1.3.5-py3-none-any.whl (120.0 kB view details)

Uploaded Python 3

File details

Details for the file tketool_core-1.3.5.tar.gz.

File metadata

  • Download URL: tketool_core-1.3.5.tar.gz
  • Upload date:
  • Size: 107.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.4

File hashes

Hashes for tketool_core-1.3.5.tar.gz
Algorithm Hash digest
SHA256 9031062becf3893100c3d3aca0ee5c1a6885a3ae2f8e8716b9108653b5a1c22f
MD5 71b99ae4413dead345ca7dce9a0609f9
BLAKE2b-256 7d5274da123741634181cc14eff0fb2d8c9d211f81abfb7c5cda01a8a83b4792

See more details on using hashes here.

File details

Details for the file tketool_core-1.3.5-py3-none-any.whl.

File metadata

  • Download URL: tketool_core-1.3.5-py3-none-any.whl
  • Upload date:
  • Size: 120.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.4

File hashes

Hashes for tketool_core-1.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5b461a2e3e5879c2a51da63bfe94a40cc492caad7303788077924b63ce1b1abe
MD5 0b790fb1addcb53170989ca082c20f99
BLAKE2b-256 1be8b9519f7e88cbdde21bbf148828516be8d346191173ba06ce09e11406b9de

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.3.5 This release

2 files

1.3.4

2 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