Skip to main content

High-performance embedded database with Rust core and Python API

Project description

ApexBase

High-performance embedded database with Rust core and Python API

ApexBase 是一个基于 Rust 核心的高性能嵌入式数据库,提供简洁的 Python API。

✨ 特性

  • 🚀 高性能 - Rust 核心,批量写入速度可达 97万+ ops/s
  • 📦 单文件存储 - 自定义 .apex 文件格式,无需外部依赖
  • 🔍 全文搜索 - 集成 NanoFTS,支持中文和模糊搜索
  • 🐍 Python 友好 - 简洁的 API,支持 Pandas/Polars/PyArrow
  • 💾 紧凑存储 - 相比传统方案节省约 45% 存储空间

📦 安装

# 从 PyPI 安装
pip install apexbase

# 从源码构建(推荐在 conda dev 环境中)
# conda activate dev
maturin develop --release

🚀 快速开始

from apexbase import ApexClient

# 创建客户端
client = ApexClient("./data")

# 存储数据
client.store({"name": "Alice", "age": 30, "city": "Beijing"})
client.store([
    {"name": "Bob", "age": 25},
    {"name": "Charlie", "age": 35}
])

# SQL 查询(推荐)
results = client.execute("SELECT * FROM default WHERE age > 28")

# 也支持传入过滤表达式(兼容用法)
results2 = client.query("age > 28", limit=100)

# 按 _id 检索(_id 为内部自增 ID)
record = client.retrieve(0)
all_data = client.retrieve_all()

# 全文搜索
client.init_fts(index_fields=["name", "city"], lazy_load=True)
doc_ids = client.search_text("Alice")
records = client.search_and_retrieve("Beijing")

# 转换为 DataFrame
df = results.to_pandas()
pl_df = results.to_polars()

# 关闭连接
client.close()

📊 性能对比

操作 ApexBase (Rust) 传统方案 提升
批量写入 (10K) 17ms 57ms 3.3x
单条检索 0.01ms 0.4ms 40x
批量检索 (100) 0.08ms 1.1ms 14x
存储大小 2.1 MB 3.9 MB 1.8x 更小

📁 项目结构

ApexBase/
├── apexbase/                    # 主包目录
│   ├── src/                     # Rust 源代码
│   │   ├── storage/             # 存储引擎
│   │   ├── table/               # 表管理
│   │   ├── query/               # 查询执行器
│   │   ├── index/               # B-tree 索引
│   │   ├── cache/               # LRU 缓存
│   │   ├── data/                # 数据类型
│   │   └── python/              # PyO3 绑定
│   ├── python/                  # Python 包装层
│   │   └── apexbase/
│   │       └── __init__.py      # Python API
│   ├── Cargo.toml
│   └── pyproject.toml
├── Cargo.toml                   # 工作区配置
└── pyproject.toml               # 项目配置

🔧 API 参考

ApexClient

# 初始化
client = ApexClient(
    dirpath="./data",           # 数据目录
    drop_if_exists=False,       # 是否删除已存在的数据
    batch_size=1000,
    enable_cache=True,
    cache_size=10000,
    prefer_arrow_format=True,
    durability="fast",         # fast | safe | max
)

# 表操作
client.create_table("users")
client.use_table("users")
client.drop_table("users")
tables = client.list_tables()

# CRUD 操作
client.store({"key": "value"})
client.store([{...}, {...}])
record = client.retrieve(0)
records = client.retrieve_many([1, 2, 3])
client.replace(0, {"new": "data"})
client.delete(0)
client.delete([1, 2, 3])

# 查询
results = client.query("age > 30")
results = client.query("name LIKE 'A%'")
results = client.execute("SELECT name, age FROM default ORDER BY age DESC LIMIT 10")
count = client.count_rows()

# 全文搜索
client.init_fts(index_fields=["title", "content"], lazy_load=True)
ids = client.search_text("keyword")
ids = client.fuzzy_search_text("keywrd")  # 模糊搜索
records = client.search_and_retrieve("keyword")

# 数据框架集成
client.from_pandas(df)
client.from_polars(df)
results.to_pandas()
results.to_polars()
results.to_arrow()

🧪 开发与测试

# 运行测试(conda dev 环境推荐)
# conda activate dev
python run_tests.py

# 或直接 pytest
pytest -q

📦 发布流程(GitHub Actions)

当前仓库已提供基于 tag 的自动构建与发布流程:当推送 v* tag 时,会运行测试、构建 wheels/sdist 并使用 twine 发布到 PyPI。

  • Workflow: .github/workflows/build_release.yml
  • Tag: v0.2.2 这类格式
  • Secret: PYPI_API_TOKEN

📚 文档

项目文档入口:docs/README.md

📄 License

Apache-2.0

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

apexbase-0.2.2.tar.gz (270.1 kB view details)

Uploaded Source

Built Distributions

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

apexbase-0.2.2-cp313-cp313-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.13Windows x86-64

apexbase-0.2.2-cp313-cp313-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

apexbase-0.2.2-cp312-cp312-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.12Windows x86-64

apexbase-0.2.2-cp312-cp312-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

apexbase-0.2.2-cp311-cp311-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.11Windows x86-64

apexbase-0.2.2-cp311-cp311-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

apexbase-0.2.2-cp310-cp310-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.10Windows x86-64

apexbase-0.2.2-cp310-cp310-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

apexbase-0.2.2-cp39-cp39-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.9Windows x86-64

apexbase-0.2.2-cp39-cp39-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

apexbase-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file apexbase-0.2.2.tar.gz.

File metadata

  • Download URL: apexbase-0.2.2.tar.gz
  • Upload date:
  • Size: 270.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for apexbase-0.2.2.tar.gz
Algorithm Hash digest
SHA256 429202f56931d49c837ec1b7ac1ec67c12716768ef4e112f0a248a8c1f2bb574
MD5 3ac14b1b990944c037e9f1f81238c0f9
BLAKE2b-256 474327185b4e1fac78017a28170d3764335b1fea96fb70b9669399b3ec8e9a25

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: apexbase-0.2.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for apexbase-0.2.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b5b4b10e457af2a961c1dbada64f471bd1af59bcea251b6e5ffd24c69446278e
MD5 238b61263445e085224e46c211f69425
BLAKE2b-256 8e3ed85534fa4652f830cd14bd6ee42efcb6ea7c64241eb31eabe4d534d168ec

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for apexbase-0.2.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1f7ff5880b2c676ec6b8fc3591ea45d995f862e94ec1b739d85cc44abc665f63
MD5 2b537e64859b00fb30bfca405f6b6d5e
BLAKE2b-256 5f12108f740cf0281f34c65b3b70ccacd6edb3f696a369d809951d4ea15f2a79

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: apexbase-0.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for apexbase-0.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 efebbcaf35ce522414e6233c5b7168119a21e350469d9c286714756ee107ebe7
MD5 5b1e8aa69045675d7c102ad2a143e082
BLAKE2b-256 ab0a31bf8a9a43c2b2d1d395fe23e9ee265c07aa9f1d876245dbf69b1db4b977

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for apexbase-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4892921c5bd78d6abb4058d7a3100640378f4559e7910fb77649a7e442e8959b
MD5 78229495b3378f8dfe3c96923abefb16
BLAKE2b-256 73c226991a28323e22fcec094a5659b3c1a92af71749843eb41baca214ba5ccc

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: apexbase-0.2.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for apexbase-0.2.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8f99f0749bf92749f8cde1eeff95ce73eba0384eae1ab2fe34a6446401180034
MD5 997842f433fa3dc761ca9ee38cdb71f8
BLAKE2b-256 d3a2498a8e1a304c32539bb233565c04c0cf6a3a626444d4b97c911515e0de9a

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for apexbase-0.2.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 163b2b781301db0130784241e55f55daa9c6ec800d28d5ce0d175d6f2055b27a
MD5 6557044daa91fd29b9ff468fbbf859fe
BLAKE2b-256 d104bf0b3f534f9ab0ca3fffcf8519cf094de573a6b4ade0f34b7a6bdc346773

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: apexbase-0.2.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for apexbase-0.2.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 12d4b476a67cf795b0746413fbbc29f067270de33fe3495e1b9c5a7d8406b117
MD5 d1ac54d47ac4733bc52fcc12f8d28b4a
BLAKE2b-256 3ede6d3c83b907661356ccb8f6248d1c55b668fff7d3fe9091a59ae33019213f

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for apexbase-0.2.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7ad3a1b6e3acfcc83a970ac4619b304d90fc12ecb66c2d11a3c630b8664b5b90
MD5 6722c566d10be14d660dc9be5be9fa59
BLAKE2b-256 83a868b814dfac924c94d502fdc381e9dcc31c9c65607ed5c1345f5100417cf7

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: apexbase-0.2.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for apexbase-0.2.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a5fa80793e668c7683d722073077a7a88743c266fe22d6bbc9092ba1deb47b31
MD5 c081245cdace0ee17968fd4701727116
BLAKE2b-256 45376ecaf41440ff306e26b5ad6c813da2eb674007eb2351fd2ca83886978c17

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for apexbase-0.2.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 345b6f797eaa8bb3b3c584aed3dc9d4ba893fde6b67b23a0765b5692fa97b6c9
MD5 aabb16d72665bbca8bff9756fff50b5f
BLAKE2b-256 37b971239e1875289d95a6e7eb8b93587536eb77a3e1e1f6e34d1c2a74cb6457

See more details on using hashes here.

File details

Details for the file apexbase-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for apexbase-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dd5a6f82ff8ddac420bd9fee8db936874af6cdc5850d46a93b97c114cb9277c9
MD5 fc01982b0e140e4cbed8b4c7e16dcf6c
BLAKE2b-256 ec77019721478dec117b8a9185be61415470deb85eb5339a28eca1a100284406

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