Skip to main content

Read DBF Files with Python

Project description

GitHub Workflow Status CodeCov Test Coverage PyPI - Python Versions

DBF is a file format used by databases such dBase, Visual FoxPro, and FoxBase+. This library reads DBF files and returns the data as native Python data types for further processing. It is primarily intended for batch jobs and one-off scripts.

>>> from dbfread import DBF
>>> for record in DBF('people.dbf'):
...     print(record)
OrderedDict([('NAME', 'Alice'), ('BIRTHDATE', datetime.date(1987, 3, 1))])
OrderedDict([('NAME', 'Bob'), ('BIRTHDATE', datetime.date(1980, 11, 12))])

By default records are streamed directly from the file. If you have enough memory you can instead load them into a list. This allows for random access:

>>> table = DBF('people.dbf', load=True)
>>> print(table.records[1]['NAME'])
Bob
>>> print(table.records[0]['NAME'])
Alice

Full documentation at https://dbfread.readthedocs.io/

See docs/changes.rst for a full list of changes in each version.

Main Features

  • simple but flexible API

  • data is returned as native Python data types

  • records are ordered dictionaries, but can be reconfigured to be of any type

  • aims to handle all variants of DBF files. (Currently only widely tested with Visual FoxPro, but should work well with other variants.)

  • support for 18 field types. Custom types can be added by subclassing FieldParser

  • reads FPT and DBT memo files, both text and binary data

  • handles mixed case file names gracefully on case sensitive file systems

  • can retrieve deleted records

Installing

Requires Python 3.6+

pip install catalystcoop.dbfread

dbfread is a pure Python module and doesn’t depend on any packages outside the standard library.

To build documentation locally:

sphinx-build docs/ docs/_build

This requires Sphinx. The resulting files can be found in docs/_build/.

Source code

http://github.com/catalyst-cooperative/dbfread/

API Changes

dbfread.open() and dbfread.read() are deprecated as of version 2.0, and will be removed in 2.2.

The DBF class is no longer a subclass of list. This makes the API a lot cleaner and easier to understand, but old code that relied on this behaviour will be broken. Iteration and record counting works the same as before. Other list operations can be rewritten using the record attribute. For example:

table = dbfread.read('people.dbf')
print(table[1])

can be rewritten as:

table = DBF('people.dbf', load=True)
print(table.records[1])

open() and read() both return DeprecatedDBF, which is a subclass of DBF and list and thus backward compatible.

License

dbfread is released under the terms of the MIT license.

Contact

Ole Martin Bjorndalen - ombdalen@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

catalystcoop.dbfread-3.0.0.tar.gz (39.4 kB view details)

Uploaded Source

Built Distribution

catalystcoop.dbfread-3.0.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file catalystcoop.dbfread-3.0.0.tar.gz.

File metadata

  • Download URL: catalystcoop.dbfread-3.0.0.tar.gz
  • Upload date:
  • Size: 39.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for catalystcoop.dbfread-3.0.0.tar.gz
Algorithm Hash digest
SHA256 e79dc93ec2e5e4dc4f9a8daac2edc5b411026301fc80bd6ceb41b453d9c7ea36
MD5 38246d47b569c23ef27b9035c9d21ddf
BLAKE2b-256 25045755774b2b32422fc067205153cc244d2ee0068cca71834561b54d748f8b

See more details on using hashes here.

File details

Details for the file catalystcoop.dbfread-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: catalystcoop.dbfread-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for catalystcoop.dbfread-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6502402a619ac580aa35ca9d00160fbd7e6c9bac928acfbf3f7d333835ea5b6
MD5 abd2d1ee3419d470edd15787928ed51b
BLAKE2b-256 a14023baf3bc0e67880a56d8e4e7550ba43690dd449b20dcf9d3c7088d0688a6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page