Skip to main content

YDbf

YDbf - reading and writing DBF/XBase files in a pythonic way. The library written in pure Python and have no external dependencies.

YDbf is compatible with Python 2.7+ and 3.5+.

What YDbf is good for:

  • export data to a DBF file
  • import data from a DBF file
  • read data from a DBF file as a stream

Where YDbf is not a good fit:

  • random access to records in a DBF file
  • memo fields

Read DBF

The entrypoint of YDbf is open function:

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

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

fh = open('simple.dbf', 'rb')
dbf = ydbf.open(fh)

for record in dbf:
    ...

You may also use with statement:

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

Each record is a dict, which keys are names of fields.

Write DBF

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

dbf = ydbf.open('simple.dbf', 'w', fields)

or open file yourself:

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

fields is a structure description of DBF file, it is a required option for write mode. The structure is as sequence of field descriptions, where each fields described by tuple (NAME, TYPE, SIZE, DECIMAL). NAME is a name of field, TYPE -- DBF type of field ('N' for number, 'C' for char, 'D' for date, 'L' for logical), DECIMAL is a precision (useful for 'N' type only). For example:

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 forthe DBF file. UTF-8 is not supported, you may use only 8-bit encodings.

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

YDbf gets data as an iterator where each item is a dict, which keys are names of fields. For example,

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)},
]

Metadata

Release files for YDbf 0.4.1

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 0.4.1
File Size Uploaded Provenance
YDbf-0.4.1.tar.gz 24.7 kB Without provenance Details

Release files / YDbf-0.4.1.tar.gz

Download URL YDbf-0.4.1.tar.gz
Size 24.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ea6098bcef11b7641a4c61454761728ab0abc54e918da90e18d5b5d89261f803
BLAKE2b-256 checksum
How to use checksums
06107b2ceb70bde10b4620f87715bbdd7a531593ea86868a0136db6570558955
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5

Security for YDbf 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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