Skip to main content

ToteDB

앱 안에 넣는 SQL 데이터베이스와, 같은 트랜잭션에 들어가는 작업 큐
CI PyPI 버전 MIT 라이선스

빠른 시작

Python 3.9 이상이 필요합니다. 가상 환경에서 설치하세요.

python3 -m venv .venv
. .venv/bin/activate
pip install totedb

Linux(x86_64·aarch64)와 macOS(arm64)용 wheel을 제공합니다. 그 밖의 POSIX 환경에서는 C 컴파일러와 GNU Make가 필요합니다.

아래 내용을 demo.py로 저장하세요. 주문 저장과 작업 등록을 한 트랜잭션으로 확정한 뒤, 작업을 꺼내 처리합니다. 예제는 임시 DB를 쓰고 실행이 끝나면 지웁니다.

from pathlib import Path
from tempfile import TemporaryDirectory

from totedb import Database, Queue

with TemporaryDirectory() as directory, Database(Path(directory) / "demo.db") as db:
    db.execute("CREATE TABLE orders (id INTEGER PRIMARY KEY, status TEXT)")
    queue = Queue(db, "shipping")
    with db.begin() as txn:
        txn.execute("INSERT INTO orders VALUES (?, ?)", [1, "paid"])
        queue.put(b"ship-order-1", txn=txn)

    claim = queue.get(lease_ms=30_000)
    print(db.execute("SELECT * FROM orders").rows)
    print(claim.payload)
    queue.ack(claim)
    print(queue.stats())
python3 demo.py
((1, 'paid'),)
b'ship-order-1'
QueueStats(ready=0, leased=0, acked=1, failed=0)

실제 데이터를 남기려면 Database("orders.db")처럼 파일 경로를 지정하세요. 큐 없이 SQL 데이터베이스로만 쓸 수도 있습니다.

여러 프로세스·언어에서 같은 큐 쓰기

Python에서 주문과 작업을 저장하고 C worker 셋이 같은 파일의 큐를 나눠 처리하는 outbox 예제가 있습니다. 작업을 받은 worker를 강제 종료한 뒤 다른 worker가 작업을 다시 받아 처리하는 과정도 확인합니다.

make example-outbox

해결하는 문제

로컬 프로그램이 주문과 출고 작업을 따로 저장하면, 주문만 저장하고 작업 등록 전에 멈출 수 있습니다. ToteDB는 SQL 테이블과 작업 큐를 같은 DB 파일에 두어 둘을 한 트랜잭션으로 확정합니다. 별도 DB 서버나 큐 서버를 띄우지 않고 앱 안에서 사용합니다.

작업은 처리 확인(ACK)을 받기 전까지 다시 전달될 수 있습니다. 메일 발송이나 외부 API 호출처럼 DB 밖에서 하는 일은 중복 실행을 견디도록 작성해야 합니다.

더 넓은 SQL 기능이 필요하면 SQLite를, 여러 writer의 동시 실행과 서버 운영 기능이 필요하면 PostgreSQL을 검토하세요.

작동 방식

  1. 앱이 Python Database.execute나 C tote_exec로 SQL을 실행합니다.
  2. 같은 트랜잭션 안에서 업무 행을 바꾸고 큐에 작업을 넣습니다.
  3. 엔진이 바뀐 페이지를 새 자리에 쓰고, 새 세대를 게시한 뒤 fsync를 마쳐 commit을 응답합니다.
  4. worker가 작업을 받아 처리하고 ACK합니다. 처리 기한(lease)이 끝나면 다른 worker가 다시 받을 수 있습니다.

업무 테이블과 큐 테이블은 같은 DB에 저장되고 worker는 그 큐에서 작업을 받아 처리한다

여러 프로세스가 같은 파일을 열 수 있지만 쓰기 트랜잭션은 한 번에 하나입니다. 이미 열린 핸들의 조회는 writer가 작업하는 동안 마지막으로 게시된 상태를 읽고, 새 세대를 게시할 때는 잠금을 기다립니다.

Python의 busy_timeout_s는 문장 실행과 쓰기 트랜잭션 시작에 적용합니다. 새 핸들을 여는 Database(...)는 재시도하지 않으므로 writer와 열기 잠금이 겹치면 DatabaseOpenError가 날 수 있습니다.

저장 방식과 잠금 규칙은 아키텍처에 있습니다.

상태

0.1.0 릴리스와 Python 패키지를 배포했습니다. 1.0 전에는 파일 형식과 API가 예고 없이 바뀔 수 있습니다.

있는 것 아직 없는 것 다음
SQL 조회·갱신, JOIN·집계·서브쿼리, 정수 기본 키·TEXT 색인 ALTER TABLE, 복합 색인, 창 함수 기본 키 조회 성능 측정 마무리 #158
단일 writer, 여러 프로세스의 파일 공유, commit 후 복구 여러 writer 동시 commit, 네트워크 파일 시스템 지원 없음
ACK 큐, 처리 기한·연장, 중복 등록 키, C·Python 바인딩 C·Python 외 언어 바인딩 없음

SQL 차등 시험은 SQLite와 대조하며, PostgreSQL 비교는 연결 설정이 있을 때 실행합니다. 강제 종료와 I/O 실패 시험의 결과·조건은 안전성 시험 결과에 있습니다. 실제 전원 차단은 검증하지 않았습니다.

변경 내용은 변경 기록에 있습니다.

문서

전체 문서

개발

GCC 또는 Clang, GNU Make, Python 3, pytest가 필요합니다. SQL 차등 시험에는 SQLite 개발 라이브러리도 필요합니다.

git clone https://github.com/woonyong-choi/totedb.git
cd totedb
make all
make test-all test-runner test-fault test-result
make SANITIZE=thread BUILD_DIR=build-tsan test-transaction test-session test-ack-queue
make test-sql-diff

소스의 Python 바인딩을 쓰려면 PYTHONPATH=python을 지정하세요. 검사 범위와 변경 제출 방법은 기여 안내에 있습니다.

라이선스

MIT

Metadata

Release files for totedb 0.2.0

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

Source distribution (sdist)

Source distribution for totedb 0.2.0
File Size Uploaded Provenance Actions
totedb-0.2.0.tar.gz 319.7 kB With provenance Details for totedb-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for totedb 0.2.0
File Interpreter ABI Platform Actions
totedb-0.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details for totedb-0.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
totedb-0.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64, Linux glibc 2.28+ ARM64 Details for totedb-0.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
totedb-0.2.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for totedb-0.2.0-py3-none-macosx_11_0_arm64.whl

Total release size: 2.2 MB

Release files / totedb-0.2.0.tar.gz

Download URL totedb-0.2.0.tar.gz
Size 319.7 kB
Tags Source
SHA-256 checksum
How to use checksums
741913f071b922ddf79b90da77b447f763455b8207b611096df60191506c97e0
BLAKE2b-256 checksum
How to use checksums
a03ddd2f0d2620472c1a2f4b69728fca71062d3eaad80ac923124fcd3f5bfa02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / totedb-0.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL totedb-0.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 819.4 kB
Tags Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
090a2decfdd571757e95be93d274846094eaaa01e4ebaec6ef6c707e8fbca815
BLAKE2b-256 checksum
How to use checksums
875f92ccee058dcb4e23a3ef6df11c8f5d5bfb4c8e05e50685b6a4e279d866bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / totedb-0.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL totedb-0.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 825.4 kB
Tags Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
d215c6c0ef5255c73d5e63be6a45f0be7a37a8e0622080bbb01a0f1a7518aefd
BLAKE2b-256 checksum
How to use checksums
36b73a5441ec08be010538e4713a11fdfde4e2aadff040f865c4239c77e05706
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / totedb-0.2.0-py3-none-macosx_11_0_arm64.whl

Download URL totedb-0.2.0-py3-none-macosx_11_0_arm64.whl
Size 197.3 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2a043fed9a6016150dd7d96c460417f2f42c4875569d1b29337fbf1e4146382e
BLAKE2b-256 checksum
How to use checksums
b847a8d009c1d8447a54bc09a77feed6deee07c987726f82ec3095740b7aabe4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Security for totedb 0.2.0

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.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for totedb-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

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.2.0 This release

4 release files Full 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