Firebird Database Driver (fdb)

2.0.4 · active · verified Thu Apr 16

fdb is a Python driver for the Firebird relational database, implementing the Python DB-API 2.0 specification. While its PyPI summary refers to it as a "Legacy Python driver for Firebird 2.5", it continues to be actively maintained with recent releases (v2.0.4) fixing compatibility issues up to Python 3.13. It primarily interacts with Firebird via the native client library. The project has an active, though not rapid, release cadence, with updates addressing bugs and modern Python compatibility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to a Firebird database, execute a simple query to list user-defined tables, and fetch the results using the `fdb` driver. It includes basic error handling and uses environment variables for sensitive connection details, which should be replaced with actual values or more secure methods in production.

import fdb
import os

# Ensure the Firebird client library (fbclient.dll/.so) is installed and discoverable.
# Replace with your Firebird database path and credentials.
DB_DSN = os.environ.get('FDB_DSN', 'localhost:/opt/firebird/data/test.fdb')
DB_USER = os.environ.get('FDB_USER', 'sysdba')
DB_PASSWORD = os.environ.get('FDB_PASSWORD', 'masterkey')

try:
    # Establish a connection to the Firebird database
    con = fdb.connect(dsn=DB_DSN,
                      user=DB_USER, 
                      password=DB_PASSWORD)
    print("Successfully connected to Firebird database.")

    # Create a cursor object
    cur = con.cursor()

    # Execute a SQL query
    cur.execute("SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG = 0")

    # Fetch and print results
    print("\nUser-defined tables:")
    for row in cur:
        print(f"- {row[0].strip()}") # RDB$RELATION_NAME is CHAR, needs stripping

    # Close the cursor and connection
    cur.close()
    con.close()
    print("\nConnection closed.")

except fdb.Error as e:
    print(f"Failed to connect or query Firebird database: {e}")
    print("Please ensure Firebird server is running, the client library is installed,")
    print("and the DSN/credentials are correct.")

view raw JSON →