Registry / database / dbfread

dbfread

JSON →
library2.0.7pypypi✓ verified 25d ago

dbfread is a pure Python library designed to read DBF files (used by databases like dBase, Visual FoxPro, and FoxBase+). It processes the data and returns it as native Python data types, making it ideal for batch jobs and one-off scripts. The current version is 2.0.7, and while stable, it is not actively developed, with its last update being in late 2016.

pip install dbfread
INSTALL
IMPORT
SIG · DBFREAD
D
dbfread
databasepythonv2.0.7
Install
1.6s avg
Import
14ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.012s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.016s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DBF
from dbfread import DBF
open
from dbfread import DBF
from dbfread import open
The `dbfread.open()` function is deprecated since version 2.0 and will be removed in 2.2. Instantiate the `DBF` class directly instead.
read
from dbfread import DBF
from dbfread import read
The `dbfread.read()` function is deprecated since version 2.0 and will be removed in 2.2. Instantiate the `DBF` class directly instead, using `load=True` if random access to records is needed.

This quickstart demonstrates how to open a DBF file and iterate through its records. It also shows how to load all records into memory if random access by index is required. It assumes a 'people.dbf' file exists for demonstration.

import datetime from dbfread import DBF # For this example to run, ensure 'people.dbf' exists in the same directory # or provide a full path. A dummy 'people.dbf' might look like: # NAME BIRTHDATE # Alice 1987-03-01 # Bob 1980-11-12 # Open the DBF file and iterate through records (streaming, memory-efficient) print("Streaming records:") try: for record in DBF('people.dbf'): print(record) except Exception as e: print(f"Error reading DBF: {e}. Please ensure 'people.dbf' exists in the current directory.") # Load all records into memory for random access (if needed) print("\nLoading all records into memory for random access:") try: table = DBF('people.dbf', load=True) print(f"First record name: {table.records[0]['NAME']}") print(f"Total records: {len(table.records)}") except Exception as e: print(f"Error reading DBF with load=True: {e}. Please ensure 'people.dbf' exists.")
Debug
Known issues
breakingThe functions `dbfread.open()` and `dbfread.read()` are deprecated since version 2.0 and are scheduled for removal in version 2.2. Direct list-like access on the `DBF` object (e.g., `table[0]`) no longer works by default since version 1.1.0.
fix
Always instantiate the `DBF` class directly (e.g., `table = DBF('filename.dbf')`). For list-like access, pass `load=True` to the `DBF` constructor, then access records via `table.records[index]` (e.g., `DBF('filename.dbf', load=True).records[0]`).
affects: >=2.0
gotchaCharacter encoding issues are common with DBF files. While `dbfread` attempts to detect the encoding, it may fall back to `ASCII` (since 1.1.0) or `latin1` (older versions), leading to `UnicodeDecodeError` or incorrect characters.
fix
If character encoding issues arise, explicitly specify the correct encoding using the `encoding` parameter in the `DBF` constructor (e.g., `DBF('file.dbf', encoding='cp1252')`). Common encodings include 'latin1', 'cp1252', or 'utf-8'.
affects: All
gotchaMemo files (`.fpt`, `.dbt`) associated with DBF files can cause issues if missing or if file casing on non-Windows systems (e.g., Linux) prevents detection (as Windows filenames are case-preserving).
fix
To handle missing memo files, pass `ignore_missing_memofile=True` to the `DBF` constructor to suppress `MissingMemoFile` exceptions. If case sensitivity is an issue, consider passing `ignorecase=False` if you know the exact casing of your memo file.
affects: All
gotchaDBF field names are typically uppercase. When accessing fields as dictionary keys, this might be inconvenient in Python where lowercase conventions are common.
fix
Use the `lowernames=True` parameter in the `DBF` constructor to automatically convert all field names to lowercase, allowing access like `record['fieldname']` instead of `record['FIELDNAME']`.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dbfread'
The 'dbfread' library has not been installed in the Python environment where the code is being executed.
fix
pip install dbfread
UnicodeDecodeError: 'ascii' codec can't decode byte 0x... in position ...: ordinal not in range(128)
The `dbfread` library failed to automatically detect the correct character encoding of the DBF file, causing a decoding error when encountering non-ASCII characters.
fix
from dbfread import DBF; table = DBF('your_file.dbf', encoding='latin1') # Try different encodings like 'cp1252', 'cp850', 'utf-8' if 'latin1' doesn't work.
dbfread.exceptions.DBFNotFound: File not found: 'your_file.dbf'
The specified DBF file does not exist at the provided path or the file path is incorrect.
fix
from dbfread import DBF; table = DBF('correct/absolute/or/relative/path/to/your_file.dbf')
dbfread.exceptions.MissingMemoFile: Missing memo file 'your_file.fpt'
The DBF file references a memo file (e.g., .fpt or .dbt) that is either missing from the expected location or its name does not match.
fix
from dbfread import DBF; table = DBF('your_file.dbf', ignore_missing_memofile=True) # or ensure the correct memo file is in the same directory as the .dbf file.
Upgrade
Version history
2.0.7latest on PyPI · released Nov 25, 2016
Audit
Dependencies

No dependency data recorded yet.

Agent activity
35 hits · last 30 days
node
29
Amazon
1
OpenAI (training)
1
Resources