paradox-db-py
Pure-Python reader and writer for Paradox tables (.DB data, .MB memos
and BLOBs, .PX primary index), versions 3.0 to 7. No native code, no copyleft
dependencies, no silent conversions: every cell comes back as OK, NULL or
INVALID together with its raw bytes.
Versión en español: README.es.md.
Patterns developed during my work at Intervalor Data and published with permission. Independent clean-room implementation with synthetic data; it contains no code or data from the company or its clients.
1. The problem
A fixed-asset management system written in Delphi on top of the Borland Database Engine kept decades of history in Paradox tables. Modernising it meant two things at once:
- Extract every record without loss. Not "most records": the legacy engine left records in the data blocks that the header never counted, and whole columns of monetary values stored as BCD that no longer decoded.
- Give tables back to the legacy application during a long transition, so the old and the new system could coexist for months.
The Python ecosystem offered only bindings over a C library (GPL) that is read-only in practice, forces one global text encoding, skips the records the header does not declare and corrupts its memory heap after a few dozen write operations. For an on-premise product none of that was acceptable.
2. Constraints
| Constraint | Consequence in the design |
|---|---|
| Distributed on-premise inside a commercial product | Pure Python, MIT licence, zero runtime dependencies |
| Real tables hold personal and financial data of third parties | Every fixture is generated by paradoxdb.synthetic; the repo contains no .DB file |
| The cipher of encrypted tables is only available in GPL code | Decryption is delegated to an optional external Decryptor; this library only decodes plain bytes |
| The legacy engine must still open what we write | The writer copies an existing header (template) and only rewrites counters; new files are produced, nothing is modified in place |
| Mixed code pages in one dataset (CP437 core, CP1252 later tables) | Code page per table, read from the header, never global |
| Monetary amounts and 32-digit BCD | Decimal everywhere; float only as the on-disk representation |
3. Architecture
paradoxdb/
├── fields.py FieldType, FieldDef, code pages, physical sizes
├── numeric.py order-preserving codecs: Paradox int, Paradox double, BCD
├── values.py CellValue(state, value, raw_bytes, reason); decode_value; encode_*
├── header.py TableHeader, parse_header, patch_counters (0x06, 0x0A-0x10, 0x49)
├── blocks.py block-chain walker (every record, anomalies) and block packer
├── memo.py MemoPointer, MemoFile (types 2 and 3), MemoWriter (type 2)
├── table.py open_table, ParadoxTable, Record, Decryptor protocol
├── writer.py write_table on a template, WriteRecord, legacy_sort_key
├── index.py DataBlock, read_data_blocks, build_index, verify_index
├── profile.py profile_table, export_csv, export_json
├── cli.py paradoxdb profile | export | verify-index
└── synthetic.py table factory used by tests and examples
Reading pipeline:
.DB bytes ──► parse_header ──► iter_blocks ──► decode_value per field ──► Record
│ ▲
└── code page, descriptors └── MemoFile (.MB sibling, any case)
Writing pipeline:
template .DB header ──copy──► patch counters ──► pack_blocks(records) ──► new .DB
template .MB first block ──► MemoWriter (one single-block entry per memo) ──► new .MB
template .PX header ──► build_index(read_data_blocks(new .DB)) ──► new .PX
Quick start
from paradoxdb import open_table
table = open_table("ASSETS.DB") # finds assets.mb / ASSETS.MB too
print(table.header.version_label, table.header.codec)
for record in table.records(): # every record in every block
amount = record["Amount"] # case-insensitive field lookup
if amount.is_ok:
total = amount.value # Decimal, date, int, bool, str, bytes
else:
print(amount.state, amount.reason, amount.raw_bytes.hex())
print(table.block_record_count(), table.declared_record_count, table.header_mismatch)
from paradoxdb import WriteRecord, write_table, verify_index, read_data_blocks
records = [
WriteRecord(r.raw_bytes, {3: r["Note"].value.encode(table.codec)}) for r in table.records()
]
result = write_table("ASSETS.DB", "out/ASSETS.DB", records, sort=False)
assert verify_index(result.px_path, read_data_blocks(result.db_path)) == []
paradoxdb profile ./tables --output profile.json # aggregates, SHA-256, mismatches
paradoxdb export ./tables/ASSETS.DB --format csv # value, state and reason per cell
paradoxdb verify-index ./tables/ASSETS.DB # exit 1 when the .PX is inconsistent
4. Decisions and the alternatives they replaced
| Decision | Rejected alternative | Why |
|---|---|---|
| Own reader in pure Python | Bindings over the C library | GPL licence, one global encoding, skips undeclared records, no 64-bit guarantee on Linux |
| Decryption delegated to an optional component | Re-implement the cipher | The only public implementation is GPL; encrypted tables are a small minority |
| Explicit state per cell plus raw bytes | None / 0 when in doubt |
The earlier approach turned garbage currency values and sentinel dates into None: silent loss at scale |
Decimal for doubles and BCD |
float |
Accounting amounts and 32-digit BCD; arithmetic parity with the legacy engine is the consumer's job |
| Code page per table | Global latin1 or cp1252 |
latin1 accepts every byte but misreads ñ / º from CP437 tables; datasets mix code pages |
| Header copied from a template | Build headers from scratch | Keeps version, descriptors, key and code page, including in empty tables, without modelling obscure header fields |
| Always new files | Modify in place | The C library corrupted memory after ~50 in-place writes |
| One single-block entry per memo | Sub-allocated blocks | Correctness first; the size cost is measured below and planned for v2 |
| Source order by default, legacy order on request | Always re-sort | The legacy engine accepts the original order; the reproduced collation matched the real one in most but not all tables |
| Whole file in memory | Block-by-block streaming | Tables of tens of MB; revisit if hundreds appear |
Decisions that the specification left open (error-message language, how the
.PX entry count is defined, how the leak guard matches words, and so on) are
listed with their rationale in docs/DECISIONES.md.
5. What was measured and how to reproduce it
Everything below runs on synthetic data produced by the repository itself.
pip install -e ".[dev]"
pytest # 100+ tests, including Hypothesis round-trip properties
python examples/benchmark.py # timings and .MB growth on a 50 000-row table
Results on a laptop-class container (Python 3.12):
| Measurement | Value |
|---|---|
| Open and decode 50 000 mixed-type records | 1.3 s |
Write .DB + .PX for those records on a template |
0.09 s |
Verify the resulting two-level .PX |
< 0.01 s |
.MB written for 5 000 memos of ~150 bytes each |
20 MiB for 0.7 MiB of payload (×27) |
The test-suite covers every case of the original specification: headers with
and without the 4.0+ extension, CP437 and CP1252 text, every field type with
sign, null versus zero, unreadable BCD, records beyond the declared count,
memos in the three storage forms, missing .MB, encrypted tables with and
without a decryptor, incoherent headers, round-trips with memos and index,
multi-level indexes, legacy collation (NA, nz, Ñu, Oa, ob), duplicate keys,
empty tables, autoincrement, secondary indexes left untouched, the index
verifier and the profile / CLI output.
In the original project the same design was validated against about 120 real tables (roughly 225 000 rows) with zero byte or value differences versus the C library, and the verifier accepted 106 of 108 original indexes (the other two had counts corrupted by interrupted writes). Those tables cannot be published; the figures are given only as context.
6. Known limits
.MBgrowth. Every memo gets at least one 4 KiB block. Sub-allocated (type 3) blocks are read but never written. Planned for v2.- Not yet opened in a real BDE. Round-trips are validated with this library's reader; opening the written files in the legacy engine is pending.
- Secondary indexes (
.Xnn,.Ynn,.XGn,.YGn) are detected and reported, never regenerated. - Encrypted tables are never written, and decryption requires an external component.
- Index entry counts are limited to 32 767 per entry, BCD to 32 digits; text that does not fit a field is an error, not a truncation.
- Whole files are loaded in memory.
7. How it was built
Three-phase clean-room process. Phase 1 produced a specification of the format,
behaviour and invariants from the original (private) code, without copying
code, identifiers or data. Phase 2, this repository, was implemented in a
separate session with access to that specification and to public documentation
only, using an AI coding assistant as pair programmer; every decision not fixed
by the specification is documented. Phase 3 is an independent review comparing
this repository against the original before publication. The CI runs a leak
guard (tests/test_no_leaks.py) over the tree and the git history, plus
gitleaks.
8. Attribution and licence
Patterns developed during my work at Intervalor Data and published with permission. Independent clean-room implementation with synthetic data; it contains no code or data from the company or its clients.
MIT licence. See LICENSE, CHANGELOG.md and CONTRIBUTING.md.
Metadata
Release files for paradoxdb 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| paradoxdb-0.1.0.tar.gz | 64.3 kB | With provenance | Details for paradoxdb-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| paradoxdb-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for paradoxdb-0.1.0-py3-none-any.whl |
Total release size: 108.2 kB
Release files / paradoxdb-0.1.0.tar.gz
| Download URL | paradoxdb-0.1.0.tar.gz |
|---|---|
| Size | 64.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
893cf2eb82ed8c49d1a7d097cef2d49d5dc77e46030dbb9e23c77930a038d8cd
|
|
BLAKE2b-256 checksum How to use checksums |
d9a668e9203f9cb67ca07064e53fbcca42722b5da6d56dd1a8fa9609c0520de2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 15, 2026.
Transparency logRelease files / paradoxdb-0.1.0-py3-none-any.whl
| Download URL | paradoxdb-0.1.0-py3-none-any.whl |
|---|---|
| Size | 43.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
39502ad11347d6e1d9e8dd5d6193e0dd214a04180ce4d2b9d7693837ec240130
|
|
BLAKE2b-256 checksum How to use checksums |
fc4aa60720534efb1eefb3d9def39a859ddbcb4c373653f89a1f84d765504536
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 15, 2026.
Transparency logSecurity for paradoxdb 0.1.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
Both files in this release have been uploaded with provenance metadata.
Attestation for paradoxdb-0.1.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 Nov 15, 2026.
Transparency logA 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.