Read GDB 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 GDB file. 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('example.gdb', '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 GDB file gets 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 Firebird GDB file to a standardized format. Then you can read the data using PHP as shown above.

Why use RebaseData?

Terms