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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pocketkit-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 a3ddaaf796addc80d20d63d4bb4f3500499f7c2d063077a3debae0d94825b8d3
MD5 7ae1cc091e17b82c620621879474216c
BLAKE2b-256 9e1e992a8105c985e96d657895ace6148286cc1e285c25936a9f7df5d5b45b43

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pocketkit-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 799a907cb7e1e980151abd3c49ec15702972574c8eac19d40d8062e3532b6edb
MD5 9f52e16b35b96d1dab315f2a2a1577fd
BLAKE2b-256 38631ce596883e1ddfbc8f1eae23fea41dfe6a08583d4cb88ac7fb6832e48ad1

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