import xorq.api as xo
con = xo.connect()
print(f"Connected to: {con}")Connected to: <xorq.backends.xorq_datafusion.Backend object at 0x7faffbbf7a40>
This guide shows you how to create a connection for each backend Xorq supports. Every connection object exposes the same expression API, so the code you write after connecting doesn’t change between engines.
For picking which backend a pipeline step should run on, see Route a step to a specific backend.
pip install "xorq[postgres]"The default backend. A modified DataFusion engine, included in the base package; it needs no setup.
In-memory by default:
For a database that survives between sessions, pass a path:
Set these environment variables, then connect with connect_env:
POSTGRES_HOSTPOSTGRES_PORTPOSTGRES_DATABASEPOSTGRES_USERPOSTGRES_PASSWORDYou can also pass credentials directly:
pg_con = xo.postgres.connect(
host="localhost",
port=5432,
database="your_database",
user="your_user",
password="your_password",
)Don’t hardcode credentials in production code. Use environment variables or the Profiles API, which stores environment-variable references instead of values.
connect creates the database file if it doesn’t exist. Point database at any path you like; this example uses a temporary one.
Whichever backend you connected to, give its variable a common name so the rest of this guide can refer to it. The examples below use the embedded backend, since it needs no setup; swap in duck_con, pg_con, or any other connection you created.
List the tables the backend can see. An empty list is fine: the connection works, there just aren’t any tables yet.
For a deeper check, run a small expression end to end:
A connection is the entry point for everything that follows: reading tables, registering data, and receiving data from other backends. Create it once and pass it around.
(<xorq.backends.xorq_datafusion.Backend object at 0x7fafeefb2db0>,)
The .ls accessor tells you which backends an expression touches, which becomes useful once a pipeline spans more than one engine.