Skip to main content

A small utility toolbox with optional modules

Project description

pocketkit

pocketkit 是一个轻量级的 Python 工具包,用于沉淀和复用项目中常用的工具函数、装饰器以及可选的基础设施封装。
设计目标是 模块化、可选依赖、长期可维护


特性

  • 📦 工具集合:将常用代码集中管理,避免项目间重复复制
  • 计时装饰器:支持同步 / 异步函数执行时间统计
  • 🔌 可选模块设计:如 nats,按需安装,不影响核心功能
  • 🧩 标准 logging:基于 Python 标准库,避免日志库冲突

安装

基础安装(不包含可选模块)

uv add pocketkit

安装 NATS 模块(可选)

uv add pocketkit[nats]

nats 模块依赖官方客户端 nats-py,通过 extras 自动安装。

计时装饰器

同步函数

from pocketkit.decorators.timing import get_time_sync

@get_time_sync
def compute(a: int, b: int) -> int:
    return a + b

compute(1, 2)

异步函数

import asyncio
from pocketkit.decorators.timing import get_time_async

@get_time_async
async def async_compute(a: int, b: int) -> int:
    await asyncio.sleep(1)
    return a + b

asyncio.run(async_compute(1, 2))

Nats

import asyncio
from pocketkit.nats import NatsConnection, EventPublisher

async def main():
    conn = await NatsConnection.create("nats://127.0.0.1:4222")

    publisher = EventPublisher(conn)
    await publisher.publish("demo.subject", b"hello world")

    await conn.close()

asyncio.run(main())

项目结构

pocketkit/
├── src/
│   └── pocketkit/
│       ├── __init__.py
│       ├── logger.py
│       ├── decorators/
│       │   ├── __init__.py
│       │   └── timing.py
│       └── nats/
│           ├── __init__.py
│           └── client.py

Project details


Download files

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

Source Distribution

pocketkit-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

pocketkit-0.1.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file pocketkit-0.1.1.tar.gz.

File metadata

  • Download URL: pocketkit-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for pocketkit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9504796f7c2e8b0f2c9470c146588a24a9d9ea94bc982bbd37316b5950eb717a
MD5 8797baec5c3d15ee8d1d2f43892b6e8c
BLAKE2b-256 09b827b5be906a8cc1f299d531d55872d461ee3ef8902dde0dfbb61da39b8bea

See more details on using hashes here.

File details

Details for the file pocketkit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pocketkit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for pocketkit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 56ac821c26f62809ec595a5e229ac4922593cec63ce2e92baca49d394539ea51
MD5 30ff9bda8296aaceb13b1bd7cf3655c5
BLAKE2b-256 6d3c97f870a21c6c99e3415032065ceb9cb19e07a2f56331c6d78643d6732703

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page