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.4.0.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.4.0-py3-none-any.whl (120.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tketool_core-1.4.0.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.4.0.tar.gz
Algorithm Hash digest
SHA256 0f575055bc553e186faa7ffd61c34ce37435f72eabc4b08808930ea97d51d3ea
MD5 74617c0e47f8656c30c44ad3d4e55e73
BLAKE2b-256 c3d6e1acd15d73115d8ee9f125347863858aef8e772549bd42fc44cf57aa5a33

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tketool_core-1.4.0-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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed6a6a63f5e659625ddb31511b8ecb7cd88346c4eb32465ebb3ed7c2b6f1b580
MD5 2a323ece32ee6a340646504836b1ec35
BLAKE2b-256 d484eac00b7e80f45b0cb5820c7f0080784c69a169f7c388269a272b4e34eec5

See more details on using hashes here.

Release history Release notifications | RSS feed

2.0.1

2 files

1.4.3

2 files

This release

1.4.0 This release

2 files

1.3.5

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