A simple tool to read DBF files, extract their metadata, and prepare for PostgreSQL table creation.
- Simple Configuration: JSON-based configuration file
- DBF Metadata Extraction: Read field names, types, lengths, and other metadata
- Clean Output: Formatted console output and optional JSON export
- Easy to Use: Simple class-based design
- Install required dependencies:
pip install -r requirements.txtUpdate the config.json file with your settings:
{
"dbf_file_path": "path/to/your/file.dbf",
"output": {
"show_metadata": true,
"show_field_details": true,
"export_to_json": false,
"json_output_path": "metadata_output.json"
},
"database": {
"host": "localhost",
"port": 5432,
"database": "your_database",
"username": "your_username",
"password": "your_password"
}
}from src.dbf_reader import DBFReader
# Initialize reader with config file
reader = DBFReader("config.json")
# Read DBF metadata
metadata = reader.read_dbf_metadata()
# Print formatted metadata
reader.print_metadata()
# Get specific information
table_name = reader.get_table_name()
field_names = reader.get_field_names()
fields_info = reader.get_fields_info()# Read a specific DBF file (overrides config)
metadata = reader.read_dbf_metadata("path/to/specific/file.dbf")# Export metadata to JSON file
json_file = reader.export_metadata_to_json("output.json")Run the test script to verify everything works:
cd src/test
python test_dbf_reader.pyDBF_meta_to_postgresql/
├── config.json # Configuration file
├── requirements.txt # Python dependencies
├── README.md # This file
└── src/
├── dbf_reader.py # Main DBF reader class
└── test/
└── test_dbf_reader.py # Test script
============================================================
DBF FILE METADATA
============================================================
File Name: example.dbf
File Path: path/to/example.dbf
File Size: 1,234 bytes
Record Count: 100
Field Count: 5
Last Modified: 2024-01-15
============================================================
FIELD INFORMATION
============================================================
Field Name Type Length Decimals Description
------------------------------------------------------------
ID N 10 0 Numeric
NAME C 50 0 Character/Text
DATE_CREATED D 8 0 Date
AMOUNT N 12 2 Numeric
ACTIVE L 1 0 Logical/Boolean
This is the first step in the DBF to PostgreSQL migration process. Future enhancements will include:
- SQL table creation query generation
- Data type mapping from DBF to PostgreSQL
- Data migration functionality
- Batch processing capabilities
- Python 3.7+
- dbf library for DBF file reading
- psycopg2-binary for PostgreSQL connectivity (future use)