Read Visual FoxPro with Python

At first make sure you have the PyPi package poster installed. On Ubuntu you can install it in the terminal like this:

apt-get install python-poster

Create a Python file example.py with the following code to read your Visual FoxPro files. Don't forget to replace the example file paths with the actual ones.

from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2

# Register the streaming http handlers with urllib2
register_openers()

# Use multipart encoding for the input files
datagen, headers = multipart_encode({ 'files[]': open('northwind.dbc', 'rb'), 'files[]': open('northwind.dct', 'rb'), 'files[]': open('northwind.dcx', 'rb'), 'files[]': open('categories.dbf', 'rb'), 'files[]': open('categories.cdx', 'rb'), 'files[]': open('categories.fpt', 'rb')})

# Create the request object
request = urllib2.Request('https://www.rebasedata.com/api/v1/convert', datagen, headers)

# Do the request and get the response
# Here the Visual FoxPro files get converted to CSV
response = urllib2.urlopen(request)

# Check if an error came back
if response.info().getheader('Content-Type') == 'application/json':
    print response.read()
    sys.exit(1)

# Write the response to /tmp/output.zip
with open('/tmp/output.zip', 'wb') as local_file:
    local_file.write(response.read())

print 'Conversion result successfully written to /tmp/output.zip!'

After running the command, try to open /tmp/output.zip. The archive contains CSV files that you can read easily with Python.

How does it work?

The RebaseData PHP-Client internally uses our API to convert the Visual FoxPro files to a standardized format. Then you can read the data using PHP as shown above.

Why use RebaseData?

Terms