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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pocketkit-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 76c41bcc15d19a65ad04ad5a254104bc9a93ed8a31f64c2867b04a5ef34306cd
MD5 2d0eb7686fd21dd6791120b21a61f103
BLAKE2b-256 6b2007b8866452c73517535fecf64fe2906c9eb07cb98208ab89f4e1fddf731d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pocketkit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a3324c6b94766352770f7079a04097ce0deb3181974e34e8a8cad2d7a779bdad
MD5 bfcdb4aed0108dc8e4d157910a15fa64
BLAKE2b-256 d45679ff577af098ee3f0227128e1ca804567f7e55507aa890fc7d9c3b991c9a

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