Skip to main content

duck-leveldb

Cross-platform LevelDB 接口,自动选择可用后端:plyvel(优先)→ ctypes + leveldb.dll(回退)。

Windows / Linux / macOS 均可使用,无需手动配置后端。

安装

pip install duck-leveldb

Windows 下 ctypes 模式需要 leveldb.dll,已内置在包中。如果不想内置,可通过 LEVELDB_DLL 环境变量指定路径。

快速开始

from duck_leveldb import LevelDB

with LevelDB("/tmp/my.db", create=True) as db:
    db.put(b"hello", b"world")
    print(db.get(b"hello"))  # b"world"

    db.delete(b"hello")
    print(db.get(b"hello"))  # None

API

LevelDB

方法 说明
LevelDB(path, create=True) 打开/创建数据库
.get(key) -> bytes | None 读取
.put(key, value) 写入
.delete(key) 删除
.iterator() -> Iterator 创建迭代器
.close() 关闭
支持 with 上下文管理器

Iterator

with db.iterator() as it:
    # 正向遍历
    for k, v in it:
        print(k, v)

    # 反向遍历
    it.seek_to_last()
    while it.valid():
        print(it.key(), it.value())
        it.prev()

    # 定位到指定 key
    it.seek(b"target")
方法 说明
.seek_to_first() 跳转到第一个 key
.seek_to_last() 跳转到最后一个 key
.seek(key) 跳转到 >= key 的位置
.next() / .prev() 前进 / 后退
.valid() -> bool 当前位置是否有效
.key() -> bytes 当前 key
.value() -> bytes 当前 value
.close() 关闭
支持 with 上下文管理器,支持 for k, v in iterator

后端

后端 条件 说明
plyvel import plyvel 成功 性能好,推荐
ctypes 回退 内置 leveldb.dll,Windows 即开即用

开发

# 测试
python scripts/run_tests.py

# 仅测试,跳过覆盖率
python scripts/run_tests.py --no-cov

# 按关键字筛选
python scripts/run_tests.py -k iterator

# 打包
python scripts/publish.py --build-only

# 发布到 PyPI
python scripts/publish.py

# 发布到 TestPyPI
python scripts/publish.py --repo testpypi

发布前需在 scripts/pypi_config.toml 中填入 PyPI token(参考 scripts/pypi_config.toml.example)。

Metadata

Release files for duck-leveldb 1.0.0.post20260620

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

Source distribution (sdist)

Source distribution for duck-leveldb 1.0.0.post20260620
File Size Uploaded Provenance
duck_leveldb-1.0.0.post20260620.tar.gz 340.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for duck-leveldb 1.0.0.post20260620
File Interpreter ABI Platform
duck_leveldb-1.0.0.post20260620-py3-none-any.whl Python 3 none any Details

Total release size: 680.0 kB

Release files / duck_leveldb-1.0.0.post20260620.tar.gz

Download URL duck_leveldb-1.0.0.post20260620.tar.gz
Size 340.3 kB
Tags Source
SHA-256 checksum
How to use checksums
03bb84b07277e522daf3ba01b84bcab1c9dc5457e294c680a4b6f9b1eecc9b9d
BLAKE2b-256 checksum
How to use checksums
f6eef2e6ef62924f002ae4fe428ed3f43de7196ce45d307340c1a2210a3458d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release files / duck_leveldb-1.0.0.post20260620-py3-none-any.whl

Download URL duck_leveldb-1.0.0.post20260620-py3-none-any.whl
Size 339.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d3052276efeea97d3a16004b50f6b0fd08efe0fa609538e8ed078cf705bc65a
BLAKE2b-256 checksum
How to use checksums
1e2c8cef78915c837ca47c237f01f7699a117aa9808abe4ff68f114fcba85d0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Security for duck-leveldb 1.0.0.post20260620

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.

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