agate-dbf

0.2.4 · active · verified Wed Apr 15

agate-dbf is a Python library that extends the `agate` data analysis library by adding robust read support for DBF (database file) files. It is currently at version 0.2.4. The library maintains an active development status, primarily releasing updates to ensure compatibility with newer Python versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a DBF file into an `agate.Table` using the `from_dbf` method. Ensure you have a `.dbf` file available; a simple way to create one for testing is provided in the comments.

import agate
import agatedbf
import os

# Create a dummy .dbf file for demonstration purposes
# In a real scenario, you would already have a .dbf file.
# For local testing, you might use a library like `dbf` or create one manually.
# Example: (requires `pip install dbf`)
# import dbf
# db = dbf.Table('test.dbf', 'name C(15); age N(3,0)')
# db.open()
# db.append({'name': 'Alice', 'age': 30})
# db.append({'name': 'Bob', 'age': 24})
# db.close()

# Ensure a dummy dbf file exists for this example to run.
# We'll simulate this by checking for a non-existent file path
# or asking the user to create one.

dbf_path = 'test.dbf'
if not os.path.exists(dbf_path):
    print(f"Please create a dummy DBF file named '{dbf_path}' with some data.")
    print("You can use `dbf` library for this (pip install dbf) or any other DBF creator.")
    print("Example: `db = dbf.Table('test.dbf', 'name C(15); age N(3,0)'); db.open(); db.append({'name': 'Alice', 'age': 30}); db.close()`")
else:
    table = agate.Table.from_dbf(dbf_path)
    print("Table loaded successfully:")
    table.print_structure()
    table.print_table(max_rows=5)

view raw JSON →