Skip to content

Instantly share code, notes, and snippets.

@rubgithub
Created November 7, 2023 21:07
Show Gist options
  • Save rubgithub/0cc0663dc067568af25e254bc0d93a47 to your computer and use it in GitHub Desktop.
Save rubgithub/0cc0663dc067568af25e254bc0d93a47 to your computer and use it in GitHub Desktop.
Python Firebird SQLAlchemy Connection (windows)
from sqlalchemy import create_engine, text
import os
# I'm using the 'portable' version of firebird 2.5 32bits and Python 3.11 32bits
# setting the firebird client path
os.environ['PATH'] = r'D:\Portable\database\firebird\Firebird25\bin;%PATH%'
# if you're running on the cmd line terminal set the path:
# set PATH=D:\Portable\database\firebird\Firebird25\bin;%PATH%
#database string connection
db_uri = 'firebird+fdb://sysdba:masterkey@localhost:3050/C:/mydata/data.fdb'
engine = create_engine(db_uri, echo=True)
# Create a connection
conn = engine.connect()
# Execute a SQL query
result = conn.execute(text('SELECT FIRST 1 * FROM MyTable'))
# Iterate through the results
for row in result:
print(row)
# Close the connection
conn.close()
sqlalchemy
sqlalchemy-firebird
packaging
fdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment