dbc-to-dbf
A pure Python utility to convert .dbc files into standard .dbf format — commonly used in public health data from the Brazilian government.
.dbc files are a compressed form of .dbf (dBase format) files used by DATASUS, the Department of Informatics of the Brazilian Unified Health System (SUS).
DATASUS provides large-scale public health datasets (such as hospital admissions, mortality records, disease surveillance, and more) in .dbc format to reduce file size and facilitate distribution.
These .dbc files are compressed using a legacy algorithm known as PKWare DCL "implode", originally used in older versions of ZIP files. This format is no longer widely supported, and modern decompression libraries (like zipfile or gzip) do not handle .dbc files.
This project provides a pure Python implementation of the BLAST decompression algorithm, which is compatible with the compression used in .dbc files. It is a direct, object-oriented rewrite of blast.c by Mark Adler (co-author of zlib), adapted and modernized for Python usage.
With this library, researchers, data analysts, public health professionals, and developers can easily extract health data from DATASUS in a readable and processable format — enabling analysis, dashboards, research, and more.
References
- DATASUS homepage: https://datasus.saude.gov.br
- File format documentation (Portuguese): https://ftp.datasus.gov.br/
- Compression format background: https://github.com/madler/blast
📦 Installation
Install directly from PyPI:
pip install dbc-to-dbf
Or clone from GitHub and install locally:
git clone https://github.com/mozaru/dbc-to-dbf.git
cd dbc-to-dbf
pip install .
🚀 Usage
➤ Option 1: Import and use in Python code
from dbctodbf import DBCDecompress
dbc = DBCDecompress()
dbc.decompressFile("input.dbc", "output.dbf")
➤ Option 2: Run as a module
python -m dbctodbf input.dbc output.dbf
➤ Option 3: Use CLI command (installed with pip)
dbc2dbf input.dbc output.dbf
🔧 Features
- Fully implemented in pure Python (no native extensions)
- Converts
.dbc(compressed DBF) to.dbf - Based on Mark Adler's
blast.c, adapted and improved using modern Python - Object-oriented design for easy integration and reuse
- Easily testable and extendable
🖥️ Example CLI script (for custom use)
import sys
from dbctodbf import DBCDecompress
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Uso: python script.py <entrada.dbc> <saida.dbf>")
sys.exit(1)
input_file = sys.argv[1]
output_file = sys.argv[2]
try:
dbc2dbf = DBCDecompress()
dbc2dbf.decompressFile(input_file, output_file)
print(f"Conversão concluída: {output_file}")
except Exception as e:
print(f"Erro ao converter: {e}")
sys.exit(1)
🔗 Links
- 📂 GitHub: https://github.com/mozaru/dbc-to-dbf
- 📦 PyPI: (coming soon)
🧑💻 Contributing
Pull requests are welcome!
If you find a bug or have a suggestion, feel free to open an issue.
⚖️ License
This project is licensed under the zlib License (see LICENSE file).
Original decompression algorithm by Mark Adler madler@alumni.caltech.edu
Python port and enhancements by Mozar Silva mozar.silva@11tech.com.br or mozar.silva@gmail.com.br.
Release files for dbc-to-dbf 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dbc_to_dbf-1.0.1.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dbc_to_dbf-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.3 kB
Release files / dbc_to_dbf-1.0.1.tar.gz
| Download URL | dbc_to_dbf-1.0.1.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ca9c33c5790b987ee9018e253666770aca3d07f62afc84a54a137fd892fbd5f
|
|
BLAKE2b-256 checksum How to use checksums |
feb7a326a1fdeb3064274c71b08a8e9650d753559c1fbc9d8bd3650b7dc6705d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.3
|
Release files / dbc_to_dbf-1.0.1-py3-none-any.whl
| Download URL | dbc_to_dbf-1.0.1-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0f894715e295e0dc46f8d55b434719af6892899974ec1da6231f64343c9a3b3
|
|
BLAKE2b-256 checksum How to use checksums |
f95f07da0e48af71a87ee36e3b167bf11e02d482ae06c47f2c6e5e55aad6d3f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.3
|