Skip to main content

EZR Database SDK

公司内部数据库元数据 SDK,提供同步、只读的 Python 接口:

  • 多环境基础库配置,实例间连接隔离。
  • 查询品牌的业务库连接节点和分表配置。
  • 根据整数或字符串 ID 计算物理表名,兼容 C# BKDR Hash。

Python 3.10+,包名 ezr-database-sdk,导入名 ezr_database_sdk。

安装与开发

python -m venv .venv
.venv/bin/python -m pip install -e .
.venv/bin/python -m unittest discover -s tests -v

其他项目在自己的虚拟环境内安装本项目路径或已发布的 wheel:

python -m pip install /path/to/ezr-database-sdk

快速使用

复制 database.example.yaml 为私有的 database.yaml,设置选中环境的配置变量:

from ezr_database_sdk import (
    EzrDatabaseSDK, physical_table_name_by_int, physical_table_name_by_hash,
)

with EzrDatabaseSDK.from_yaml("database.yaml", env="qcloud") as sdk:
    rules = sdk.get_table_shards(brand_id=6812, database="crm")
    nodes = sdk.get_connection_strings(brand_id=6812, database="crm")
    # 计算已配置分表规则的表名:
    # table = sdk.get_physical_table_name_by_int(6812, "crm", "实际逻辑表名", 123)
    # hashed = sdk.get_physical_table_name_by_hash(6812, "crm", "实际逻辑表名", "123")

# 不连接数据库的纯计算接口:
assert physical_table_name_by_int("vip", 123, 16) == "vip12"
assert physical_table_name_by_hash("vip", "123", 16) == "vip3"

两种算法通过方法名显式选择,并严格检查参数类型,不自动转换;整数方法传入字符串、Hash 方法传入整数均会报错。旧的自动分派接口仅保留兼容并标记弃用,迁移说明见使用文档。

连接串含敏感凭据,禁止打印或写入日志。建议每个线程独立创建 SDK 实例,并使用上下文管理器关闭。

详细配置、返回字段、业务库代号、算法兼容及错误处理见 使用文档。

发布

.venv/bin/python -m pip install -e '.[release]'
.venv/bin/python upload.py --dry-run     # 预演,不修改、不上传
.venv/bin/python upload.py --build-only  # 测试、构建、校验,不改版本、不上传
# 正式发布(先配置 Twine 凭据;会递增版本并实际上传):
# .venv/bin/python upload.py

版本递增规则与 kxy/framework 一致,补丁号超过 19 时进位。仓库、凭据和故障恢复见 发布文档。

本项目从 testdata 工具项目独立迁出,不依赖其脚本、私有配置或数据库凭据。

Metadata

Release files for ezr-database-sdk 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ezr-database-sdk 0.1.2
File Size Uploaded Provenance Actions
ezr_database_sdk-0.1.2.tar.gz 24.8 kB Without provenance Details for ezr_database_sdk-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ezr-database-sdk 0.1.2
File Interpreter ABI Platform Actions
ezr_database_sdk-0.1.2-py3-none-any.whl Python 3 none any Details for ezr_database_sdk-0.1.2-py3-none-any.whl

Total release size: 33.3 kB

Release files / ezr_database_sdk-0.1.2.tar.gz

Download URL ezr_database_sdk-0.1.2.tar.gz
Size 24.8 kB
Tags Source
SHA-256 checksum
How to use checksums
78ba0d47b06971b0d20cf01a87b119e88342e76d4c91e7dd87a389864efcc97b
BLAKE2b-256 checksum
How to use checksums
a2cb28875a2021715abbce7eb7c5a8dee74f10305f3f4f34dd83c823a3b64233
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / ezr_database_sdk-0.1.2-py3-none-any.whl

Download URL ezr_database_sdk-0.1.2-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a2a762bd56fea3b4fc2342d6e4846cac08b8b5b27c4824391d2978fc9e049b7
BLAKE2b-256 checksum
How to use checksums
0cf6119a11e1d3a51cb0c87d273aa8b7b236ffe18b0b5ec626bbbcf3128127f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Security for ezr-database-sdk 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

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