{"library":"sqlalchemy-firebird","title":"Firebird for SQLAlchemy","type":"library","description":"SQLAlchemy-Firebird is an external dialect for SQLAlchemy, enabling Python applications to connect and interact with Firebird relational database servers. It provides a DBAPI 2.0 compliant interface, supporting both the `firebird-driver` (recommended for Python 3.8+ and Firebird 3+) and `fdb` drivers (for Python < 3.8 / SQLAlchemy 1.4+ and Firebird 2.5/3.0+). The library is actively maintained, with its current version being 2.1, and saw its last stable release in January 2024.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install sqlalchemy-firebird","pip install sqlalchemy-firebird fdb"],"cli":null},"imports":["from sqlalchemy import create_engine"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/fdcastel/sqlalchemy-firebird","docs":"https://github.com/fdcastel/sqlalchemy-firebird/wiki","changelog":null,"pypi":"https://pypi.org/project/sqlalchemy-firebird/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import os\nfrom sqlalchemy import create_engine, text\n\n# Configure Firebird connection details via environment variables\nFB_USER = os.environ.get('FIREBIRD_USER', 'sysdba')\nFB_PASSWORD = os.environ.get('FIREBIRD_PASSWORD', 'masterkey')\nFB_HOST = os.environ.get('FIREBIRD_HOST', 'localhost')\nFB_PORT = os.environ.get('FIREBIRD_PORT', '3050')\nFB_DB_PATH = os.environ.get('FIREBIRD_DB_PATH', '/opt/firebird/data/employee.fdb') # Example for Linux\n# For Windows, path might be 'C:/path/to/my_project.fdb'\n# Optional: Specify client library path if needed, e.g., 'C:/Firebird/Firebird_4_0/bin/fbclient.dll'\nFB_CLIENT_LIB = os.environ.get('FIREBIRD_CLIENT_LIBRARY', '')\n\n# Construct the connection URI. Use 'firebird+firebird' for firebird-driver (Python 3.8+)\n# or 'firebird+fdb' for fdb driver (older Python/Firebird 2.5).\n# The 'firebird' driver is assumed to be firebird-driver for Python 3.8+\ndb_uri_parts = [\n    f\"firebird+firebird://{FB_USER}:{FB_PASSWORD}@{FB_HOST}:{FB_PORT}{FB_DB_PATH}\"\n]\nif FB_CLIENT_LIB:\n    db_uri_parts.append(f\"?fb_client_library={FB_CLIENT_LIB}\")\n\ndb_uri = \"\".join(db_uri_parts)\n\nprint(f\"Attempting to connect to: {db_uri.split(':', 2)[0]}://{FB_USER}:****@{FB_HOST}:{FB_PORT}{FB_DB_PATH}\")\n\ntry:\n    engine = create_engine(db_uri, echo=True)\n\n    with engine.connect() as connection:\n        # Example: Fetch Firebird engine version\n        result = connection.execute(text(\"SELECT RDB$GET_CONTEXT('SYSTEM', 'ENGINE_VERSION') FROM RDB$DATABASE\"))\n        version = result.scalar()\n        print(f\"Successfully connected to Firebird. Engine Version: {version}\")\n        connection.commit()\n\nexcept Exception as e:\n    print(f\"Connection failed: {e}\")","lang":"python","description":"This quickstart demonstrates how to establish a connection to a Firebird database using SQLAlchemy-Firebird and the `create_engine` function. It utilizes environment variables for database credentials and paths, making it suitable for various deployments. It includes a basic query to retrieve the Firebird engine version to confirm connectivity. The example defaults to `firebird-driver` (via `firebird+firebird://`) but notes the `fdb` alternative.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}