>>> import ibis
>>> con = ibis.connect("duckdb://")Top-level connection APIs
Create and manage backend connections.
connect
ibis.connect(resource, /, **kwargs)Connect to resource, inferring the backend automatically.
The general pattern for ibis.connect is
con = ibis.connect("backend://connection-parameters")With many backends that looks like
con = ibis.connect("backend://user:password@host:port/database")See the connection syntax for each backend for details about URL connection requirements.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| resource | Path | str | A URL or path to the resource to be connected to. | required |
| kwargs | Any | Backend specific keyword arguments | {} |
Examples
Connect to an in-memory DuckDB database:
Connect to an on-disk SQLite database:
>>> con = ibis.connect("sqlite://relative.db")
>>> con = ibis.connect(
... "sqlite:///absolute/path/to/data.db"
... ) # quartodoc: +SKIPConnect to a PostgreSQL server:
>>> con = ibis.connect(
... "postgres://user:password@hostname:5432"
... ) # quartodoc: +SKIPConnect to BigQuery:
>>> con = ibis.connect(
... "bigquery://my-project/my-dataset"
... ) # quartodoc: +SKIPget_backend
ibis.get_backend(expr=None, /)Get the current Ibis backend to use for a given expression.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| expr | Expr | None |
An expression to get the backend from. If not passed, the default backend is returned. | None |
Returns
| Name | Type | Description |
|---|---|---|
BaseBackend |
The Ibis backend. |
Examples
>>> import ibisGet the default backend.
>>> ibis.get_backend()<ibis.backends.duckdb.Backend at 0x7fffb3a50b30>
Get the backend for a specific expression.
>>> polars_con = ibis.polars.connect()
>>> t = polars_con.create_table("t", ibis.memtable({"a": [1, 2, 3]}))
>>> ibis.get_backend(t)<ibis.backends.polars.Backend at 0x7fffa270b7a0>
See Also
set_backend
ibis.set_backend(backend, /)Set the default Ibis backend.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| backend | str | BaseBackend |
May be a backend name or URL, or an existing backend instance. | required |
Examples
You can pass the backend as a name:
>>> import ibis
>>> ibis.set_backend("polars")Or as a URI
>>> ibis.set_backend(
... "postgres://user:password@hostname:5432"
... ) # quartodoc: +SKIPOr as an existing backend instance
>>> ibis.set_backend(ibis.duckdb.connect())