Skip to main content

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


📦 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


🧑‍💻 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)

Source distribution for dbc-to-dbf 1.0.1
File Size Uploaded
dbc_to_dbf-1.0.1.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dbc-to-dbf 1.0.1
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

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