Ibis
What is Ibis?
Ibis is a Python library that provides a lightweight, universal interface for data wrangling. It helps Python users explore and transform data of any size, stored anywhere.
Ibis has three primary components:
- A dataframe API for Python. Python users can write Ibis code to manipulate tabular data.
- Interfaces to 15+ query engines. Wherever data is stored, people can use Ibis as their API of choice to communicate with any of those query engines.
- Deferred execution. Ibis uses deferred execution, so execution of code is pushed to the query engine. Users can execute at the speed of their backend, not their local computer.
Why Use Ibis?
Ibis aims to be a future-proof solution to interacting with data using Python and can accomplish this goal through its main features:
- Familiar API: Ibisβs API design borrows from popular APIs like pandas and dplyr that most users already know and like to use.
- Consistent syntax: Ibis aims to be a universal Python API for tabular data of any size, big or small.
- Deferred execution: Ibis pushes code execution to the query engine and only moves required data into memory when necessary. Analytics workflows are faster and more efficient
- Interactive mode: Ibis provides an interactive mode in which users can quickly diagnose problems, explore data, and mock up workflows and pipelines locally.
- 10+ supported backends: Ibis supports multiple query engines and DataFrame APIs. Use one interface to transform with your data wherever it lives: from DataFrames in pandas to Parquet files through DuckDB to tables in BigQuery.
- Minimize rewrites: Teams can often keep their Ibis code the same regardless of backend changes, like increasing or decreasing computing power, changing the number or size of their databases, or switching backends entirely.
- Flexibility when you need it: When Ibis doesn't support something, it provides a way to jump directly into SQL.
Common Use Cases
- Speed up prototype to production. Scale code written and tested locally to a distributed system or cloud SQL engine with minimal rewrites.
- Boost performance of existing Python or pandas code. For example a general rule of thumb for pandas is "Have 5 to 10 times as much RAM as the size of your dataset". When a dataset exceeds this rule using in-memory frameworks like pandas can be slow. Instead, using Ibis will significantly speed up your workflows because of its deferred execution. Ibis also empowers you to switch to a faster database engine, without changing much of your code.
- Get rid of long, error-prone,
f
-strings. Ibis provides one syntax for multiple query engines and dataframe APIs that lets you avoid learning new flavors of SQL or other framework-specific code. Learn the syntax once and use that syntax anywhere.
Backends
Ibis acts as a universal frontend to the following systems:
- Apache Arrow DataFusion (experimental)
- Apache Druid (experimental)
- Apache Impala
- Apache PySpark
- BigQuery
- ClickHouse
- Dask
- DuckDB
- HeavyAI
- MySQL
- Oracle (experimental)
- Pandas
- Polars (experimental)
- PostgreSQL
- SQL Server
- SQLite
- Snowflake (experimental)
- Trino (experimental)
The list of supported backends is continuously growing. Anyone can get involved in adding new ones! Learn more about contributing to ibis in our contributing documentation at https://github.com/ibis-project/ibis/blob/master/docs/CONTRIBUTING.md
Installation
Install Ibis from PyPI with:
pip install 'ibis-framework[duckdb]'
Or from conda-forge with:
conda install ibis-framework -c conda-forge
(Itβs a common mistake to pip install ibis
. If you try to use Ibis and get errors early on try uninstalling ibis
and installing ibis-framework
)
To discover ibis, we suggest starting with the DuckDB backend (which is included by default in the conda-forge package). The DuckDB backend is performant and fully featured.
To use ibis with other backends, include the backend name in brackets for PyPI:
pip install 'ibis-framework[postgres]'
Or use ibis-$BACKEND
where $BACKEND
is the specific backend you want to use when installing from conda-forge:
conda install ibis-postgres -c conda-forge
Getting Started with Ibis
We provide a number of tutorial and example notebooks in the ibis-examples. The easiest way to try these out is through the online interactive notebook environment provided here:
You can also get started analyzing any dataset, anywhere with just a few lines of Ibis code. Hereβs an example of how to use Ibis with a SQLite database.
Download the SQLite database from the ibis-tutorial-data
GCS (Google Cloud
Storage) bucket, then connect to it using ibis.
curl -LsS -o geography.db 'https://storage.googleapis.com/ibis-tutorial-data/geography.db'
Connect to the database and show the available tables
>>> import ibis
>>> from ibis import _
>>> ibis.options.interactive = True
>>> con = ibis.sqlite.connect("geography.db")
>>> con.tables
Tables
------
- countries
- gdp
- independence
Choose the countries
table and preview its first few rows
>>> countries = con.tables.countries
>>> countries.head()
ββββββββββββββ³βββββββββββββ³ββββββββββββββ³βββββββββ³βββββββββββββββββββββββ³βββββββββββββββββββ³βββββββββββ³βββββββββββββ³ββββββββββββ
β iso_alpha2 β iso_alpha3 β iso_numeric β fips β name β capital β area_km2 β population β continent β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β string β string β int32 β string β string β string β float64 β int32 β string β
ββββββββββββββΌβββββββββββββΌββββββββββββββΌβββββββββΌβββββββββββββββββββββββΌβββββββββββββββββββΌβββββββββββΌβββββββββββββΌββββββββββββ€
β AD β AND β 20 β AN β Andorra β Andorra la Vella β 468.0 β 84000 β EU β
β AE β ARE β 784 β AE β United Arab Emirates β Abu Dhabi β 82880.0 β 4975593 β AS β
β AF β AFG β 4 β AF β Afghanistan β Kabul β 647500.0 β 29121286 β AS β
β AG β ATG β 28 β AC β Antigua and Barbuda β St. Johns β 443.0 β 86754 β NA β
β AI β AIA β 660 β AV β Anguilla β The Valley β 102.0 β 13254 β NA β
ββββββββββββββ΄βββββββββββββ΄ββββββββββββββ΄βββββββββ΄βββββββββββββββββββββββ΄βββββββββββββββββββ΄βββββββββββ΄βββββββββββββ΄ββββββββββββ
Show the 5 least populous countries in Asia
>>> (
... countries.filter(_.continent == "AS")
... .select("name", "population")
... .order_by(_.population)
... .limit(5)
... )
ββββββββββββββββββββββββββββββββββ³βββββββββββββ
β name β population β
β‘ββββββββββββββββββββββββββββββββββββββββββββββ©
β string β int32 β
ββββββββββββββββββββββββββββββββββΌβββββββββββββ€
β Cocos [Keeling] Islands β 628 β
β British Indian Ocean Territory β 4000 β
β Brunei β 395027 β
β Maldives β 395650 β
β Macao β 449198 β
ββββββββββββββββββββββββββββββββββ΄βββββββββββββ
Community and Contributing
Ibis is an open source project and welcomes contributions from anyone in the community.
- Read the contributing guide.
- We care about keeping the community welcoming for all. Check out the code of conduct.
- The Ibis project is open sourced under the Apache License.
Join our community here:
- Twitter: https://twitter.com/IbisData
- Gitter: https://gitter.im/ibis-dev/Lobby
- StackOverflow: https://stackoverflow.com/questions/tagged/ibis
For more information visit https://ibis-project.org/.