SQLite
Install
Install Ibis and dependencies for the SQLite backend:
Install with the sqlite
extra:
pip install 'ibis-framework[sqlite]'
And connect:
import ibis
= ibis.sqlite.connect() con
- 1
- Adjust connection parameters as needed.
Install for SQLite:
conda install -c conda-forge ibis-sqlite
And connect:
import ibis
= ibis.sqlite.connect() con
- 1
- Adjust connection parameters as needed.
Install for SQLite:
mamba install -c conda-forge ibis-sqlite
And connect:
import ibis
= ibis.sqlite.connect() con
- 1
- Adjust connection parameters as needed.
Connect
ibis.sqlite.connect
Use an ephemeral, in-memory database.
= ibis.sqlite.connect() con
Connect to, or create, a local SQLite file
= ibis.sqlite.connect("mydb.sqlite") con
ibis.sqlite.connect
is a thin wrapper around ibis.backends.sqlite.Backend.do_connect
.
Connection Parameters
do_connect
do_connect(self, database=None, type_map=None)
Create an Ibis client connected to a SQLite database.
Multiple database files can be accessed using the attach()
method.
Parameters
Name | Type | Description | Default |
---|---|---|---|
database |
str | Path | None | File path to the SQLite database file. If None , creates an in-memory transient database and you can use attach() to add more files |
None |
type_map |
dict[str, str | dt.DataType] | None | An optional mapping from a string name of a SQLite “type” to the corresponding ibis DataType that it represents. This can be used to override schema inference for a given SQLite database. | None |
Examples
>>> import ibis
>>> ibis.sqlite.connect("path/to/my/sqlite.db")
ibis.connect
URL format
In addition to ibis.sqlite.connect
, you can also connect to SQLite by passing a properly formatted SQLite connection URL to ibis.connect
:
= ibis.connect("sqlite:///path/to/local/file") con
The URL can be sqlite://
which will connect to an ephemeral in-memory database:
= ibis.connect("sqlite://") con
sqlite.Backend
attach
attach(self, name, path)
Connect another SQLite database file to the current connection.
Parameters
Name | Type | Description | Default |
---|---|---|---|
name |
str | Database name within SQLite | required |
path |
str | Path | Path to sqlite3 database files | required |
Examples
>>> con1 = ibis.sqlite.connect("original.db")
>>> con2 = ibis.sqlite.connect("new.db")
>>> con1.attach("new", "new.db")
>>> con1.list_tables(database="new")
list_databases
list_databases(self, like=None)
List existing databases in the current connection.
Parameters
Name | Type | Description | Default |
---|---|---|---|
like |
str | None | A pattern in Python’s regex format to filter returned database names. | None |
Returns
Type | Description |
---|---|
list[str] | The database names that exist in the current connection, that match the like pattern if provided. |