Skip to main content

Common async Redis and MongoDB clients for VBP bid services.

Project description

vbp-bid-common

vbp-bid-common 是 VBP Bid Copilot 的公共基础包,当前提供异步 Redis 与 MongoDB 客户端封装,便于多个服务复用同一套缓存、队列、分布式锁和基础 CRUD 能力。

安装

pip install vbp-bid-common

本地开发时可在仓库根目录执行:

pip install -e ./vbp-bid-common[dev]

使用示例

from vbp_bid_common import get_mongodb_client, get_redis_client


async def main() -> None:
    redis_client = get_redis_client()
    await redis_client.set("demo:key", "value", ex=60)
    value = await redis_client.get("demo:key")

    mongo_client = get_mongodb_client(default_collection="demo")
    inserted_id = await mongo_client.insert_one({"value": value})
    doc = await mongo_client.find_one({"_id": inserted_id})

也可以按模块导入:

from vbp_bid_common.services.mongodb import MongoDBClient
from vbp_bid_common.services.redis import RedisClient

环境变量

Redis 客户端支持以下环境变量:

  • REDIS_HOST,默认 127.0.0.1
  • REDIS_PORT,默认 6379
  • REDIS_DB,默认 0
  • REDIS_USERNAME
  • REDIS_PASSWORD
  • REDIS_DECODE_RESPONSES,默认 true
  • REDIS_MAX_CONNECTIONS,默认 100
  • REDIS_CONNECTION_POOL_TIMEOUT,默认 10
  • REDIS_SOCKET_TIMEOUT
  • REDIS_SOCKET_CONNECT_TIMEOUT

MongoDB 客户端支持以下环境变量:

  • MONGODB_URI,默认 mongodb://127.0.0.1:27017
  • MONGODB_DATABASE,默认 test-technical
  • MONGODB_COLLECTION_NAME
  • MONGODB_MAX_POOL_SIZE
  • MONGODB_MIN_POOL_SIZE
  • MONGODB_SERVER_SELECTION_TIMEOUT_MS

发布到 PyPI

首次发布前需要注册并配置 PyPI API Token:

python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*
python -m twine upload dist/*

发布测试包可先使用 TestPyPI:

python -m twine upload --repository testpypi dist/*

每次发布前请更新 pyproject.toml 中的 version,并确认 README.mdLICENSE 与依赖声明已同步。

开源协议

本项目使用 Apache License 2.0。详见 LICENSE

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

vbp_bid_common-0.1.5.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

vbp_bid_common-0.1.5-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file vbp_bid_common-0.1.5.tar.gz.

File metadata

  • Download URL: vbp_bid_common-0.1.5.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for vbp_bid_common-0.1.5.tar.gz
Algorithm Hash digest
SHA256 479e8323a7dc3dea5588440da83d4087ade5d8bba9f3d5f99e6f3d8a70f0bf8a
MD5 4fe7af776e9cdd3ad59ec83839bfe033
BLAKE2b-256 592a0abc81af34eb590fc07c0fd1a1dcf7208b5aee81e118a0ff2eb8c79367e9

See more details on using hashes here.

File details

Details for the file vbp_bid_common-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: vbp_bid_common-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for vbp_bid_common-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2499b6edea7dc71f9f87c658458f48740bfed5256985cf2b5b4e5c4147dfb8ca
MD5 aafcb0ccfaab948c8169ddc7989a4b5f
BLAKE2b-256 2520cfdbd77a66fe3cec9ce6121ff22d22c35446d7320dbd1586745505064db5

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