{"id":2460,"library":"dbfread","title":"Read DBF Files with Python","description":"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.","status":"active","version":"2.0.7","language":"en","source_language":"en","source_url":"https://github.com/olemb/dbfread/","tags":["dbf","database","foxpro","dBASE","data-processing"],"install":[{"cmd":"pip install dbfread","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"DBF","correct":"from dbfread import DBF"},{"note":"The `dbfread.open()` function is deprecated since version 2.0 and will be removed in 2.2. Instantiate the `DBF` class directly instead.","wrong":"from dbfread import open","symbol":"open","correct":"from dbfread import DBF"},{"note":"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.","wrong":"from dbfread import read","symbol":"read","correct":"from dbfread import DBF"}],"quickstart":{"code":"import datetime\nfrom dbfread import DBF\n\n# For this example to run, ensure 'people.dbf' exists in the same directory\n# or provide a full path. A dummy 'people.dbf' might look like:\n# NAME      BIRTHDATE\n# Alice     1987-03-01\n# Bob       1980-11-12\n\n# Open the DBF file and iterate through records (streaming, memory-efficient)\nprint(\"Streaming records:\")\ntry:\n    for record in DBF('people.dbf'):\n        print(record)\nexcept Exception as e:\n    print(f\"Error reading DBF: {e}. Please ensure 'people.dbf' exists in the current directory.\")\n\n# Load all records into memory for random access (if needed)\nprint(\"\\nLoading all records into memory for random access:\")\ntry:\n    table = DBF('people.dbf', load=True)\n    print(f\"First record name: {table.records[0]['NAME']}\")\n    print(f\"Total records: {len(table.records)}\")\nexcept Exception as e:\n    print(f\"Error reading DBF with load=True: {e}. Please ensure 'people.dbf' exists.\")","lang":"python","description":"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."},"warnings":[{"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]`).","message":"The 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.","severity":"breaking","affected_versions":">=2.0"},{"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'.","message":"Character 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.","severity":"gotcha","affected_versions":"All"},{"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.","message":"Memo 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).","severity":"gotcha","affected_versions":"All"},{"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']`.","message":"DBF field names are typically uppercase. When accessing fields as dictionary keys, this might be inconvenient in Python where lowercase conventions are common.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}