Skip to main content

Read/write DBF (DBase/XBase) files from Python. This is a pure-Python implementation with no external dependencies.

Quickstart

pip install ydbf-py3

Reading

The entrypoint of YDbf is an open function:

dbf = ydbf.open('simple.dbf')

You can use file name, or already opened (in binary mode) file:

with ydbf.open('simple.dbf') as dbf:
    for record in dbf:
        ...

Each record is represented as dict, where keys are names of fields.

Writing

By default, YDbf opens file for reading, but you may set option mode to open for writing:

with ydbf.open('simple.dbf', 'w', fields) as dbf:
    dbf.write(data)

Or pass in a file handle:

with open('simple.dbf', 'wb') as fh:
    dbf = ydbf.open(fh, 'w', fields)

fields is a structure description of DBF file, it is required option for writing mode. Structure defined as sequence of field descriptions, where each fields described by tuple (NAME, TYP, SIZE, DEC). Where NAME is a name of field, TYPDBF type of field ('N' for number, 'C' for char, 'D' for date, 'L' for logical), DEC is a precision (useful for 'N' type only). For example, like this:

fields = [
    ('ID',      'N',  4, 0),
    ('VALUE',   'C', 40, 0),
    ('UPDATE',  'D', 8, 0),
    ('VISIBLE', 'L', 1, 0),
]

YDbf uses unicode for 'C' fields by default, so you may want to define encoding which be used for DBF file. Sadly, UTF-8 is not available, only old scrappy 8-bits.

dbf = ydbf.open('simple.dbf', 'w', fields, encoding='cp1251')
dbf.write(data)

YDbf gets data as iterator where each item is a dict, where keys are name of fields. For early defined example it may looks like

data = [
    {'ID': 1, 'VALUE': 'ydbf', 'VISIBLE': True,
        'UPDATE': datetime.date(2009, 7, 14)},
    {'ID': 2, 'VALUE': 'ydbf-dev', 'VISIBLE': False,
        'UPDATE': datetime.date(2009, 5, 15)},
    {'ID': 3, 'VALUE': 'pytils', 'VISIBLE': True,
        'UPDATE': datetime.date(2009, 5, 11)},
]

Release files for ydbf-py3 0.7.post20180112

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ydbf-py3 0.7.post20180112
File Size Uploaded
ydbf-py3-0.7.post20180112.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ydbf-py3 0.7.post20180112
File Interpreter ABI Platform
ydbf_py3-0.7.post20180112-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 39.4 kB

Release files / ydbf-py3-0.7.post20180112.tar.gz

Download URL ydbf-py3-0.7.post20180112.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1d81b819524ca0191c47057c728a2b6ef76141370574af29e0b7a299211f30ab
BLAKE2b-256 checksum
How to use checksums
34d80f3c98f6b189049e884d6d5cbd6a284ec52410384fde0380870a8d23afc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / ydbf_py3-0.7.post20180112-py2.py3-none-any.whl

Download URL ydbf_py3-0.7.post20180112-py2.py3-none-any.whl
Size 23.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e950872706b58c1e5e560b0b7fbea6769ebdf0fbc675dea72b58726575d96d6a
BLAKE2b-256 checksum
How to use checksums
2f5027d640c356bf04bf9120a600dde2788b8322bd9d46a5cd1d88851571345a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
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