ibis-framework

9.5.0last stable release 4 months ago
Complexity Score
High
Open Issues
99
Dependent Projects
37
Weekly Downloadsglobal
83,731

License

  • Apache-2.0
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Yespatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

Ibis

What is Ibis?

Ibis is the portable Python dataframe library:

  • Fast local dataframes (via DuckDB by default)
  • Lazy dataframe expressions
  • Interactive mode for iterative data exploration
  • Compose Python dataframe and SQL code
  • Use the same dataframe API for 20+ backends
  • Iterate locally and deploy remotely by changing a single line of code

See the documentation on β€œWhy Ibis?” to learn more.

Getting started

You can pip install Ibis with a backend and example data:

pip install 'ibis-framework[duckdb,examples]'

πŸ’‘ Tip

See the installation guide for more installation options.

Then use Ibis:

>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t
┏━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━┓
┃ species ┃ island    ┃ bill_length_mm ┃ bill_depth_mm ┃ flipper_length_mm ┃ body_mass_g ┃ sex    ┃ year  ┃
┑━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━┩
β”‚ string  β”‚ string    β”‚ float64        β”‚ float64       β”‚ int64             β”‚ int64       β”‚ string β”‚ int64 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Adelie  β”‚ Torgersen β”‚           39.1 β”‚          18.7 β”‚               181 β”‚        3750 β”‚ male   β”‚  2007 β”‚
β”‚ Adelie  β”‚ Torgersen β”‚           39.5 β”‚          17.4 β”‚               186 β”‚        3800 β”‚ female β”‚  2007 β”‚
β”‚ Adelie  β”‚ Torgersen β”‚           40.3 β”‚          18.0 β”‚               195 β”‚        3250 β”‚ female β”‚  2007 β”‚
β”‚ Adelie  β”‚ Torgersen β”‚           NULL β”‚          NULL β”‚              NULL β”‚        NULL β”‚ NULL   β”‚  2007 β”‚
β”‚ Adelie  β”‚ Torgersen β”‚           36.7 β”‚          19.3 β”‚               193 β”‚        3450 β”‚ female β”‚  2007 β”‚
β”‚ Adelie  β”‚ Torgersen β”‚           39.3 β”‚          20.6 β”‚               190 β”‚        3650 β”‚ male   β”‚  2007 β”‚
β”‚ Adelie  β”‚ Torgersen β”‚           38.9 β”‚          17.8 β”‚               181 β”‚        3625 β”‚ female β”‚  2007 β”‚
β”‚ Adelie  β”‚ Torgersen β”‚           39.2 β”‚          19.6 β”‚               195 β”‚        4675 β”‚ male   β”‚  2007 β”‚
β”‚ Adelie  β”‚ Torgersen β”‚           34.1 β”‚          18.1 β”‚               193 β”‚        3475 β”‚ NULL   β”‚  2007 β”‚
β”‚ Adelie  β”‚ Torgersen β”‚           42.0 β”‚          20.2 β”‚               190 β”‚        4250 β”‚ NULL   β”‚  2007 β”‚
β”‚ …       β”‚ …         β”‚              … β”‚             … β”‚                 … β”‚           … β”‚ …      β”‚     … β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜
>>> g = t.group_by("species", "island").agg(count=t.count()).order_by("count")
>>> g
┏━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┓
┃ species   ┃ island    ┃ count ┃
┑━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━┩
β”‚ string    β”‚ string    β”‚ int64 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Adelie    β”‚ Biscoe    β”‚    44 β”‚
β”‚ Adelie    β”‚ Torgersen β”‚    52 β”‚
β”‚ Adelie    β”‚ Dream     β”‚    56 β”‚
β”‚ Chinstrap β”‚ Dream     β”‚    68 β”‚
β”‚ Gentoo    β”‚ Biscoe    β”‚   124 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ’‘ Tip

See the getting started tutorial for a full introduction to Ibis.

Python + SQL: better together

For most backends, Ibis works by compiling its dataframe expressions into SQL:

>>> ibis.to_sql(g)
SELECT
  "t1"."species",
  "t1"."island",
  "t1"."count"
FROM (
  SELECT
    "t0"."species",
    "t0"."island",
    COUNT(*) AS "count"
  FROM "penguins" AS "t0"
  GROUP BY
    1,
    2
) AS "t1"
ORDER BY
  "t1"."count" ASC

You can mix SQL and Python code:

>>> a = t.sql("SELECT species, island, count(*) AS count FROM penguins GROUP BY 1, 2")
>>> a
┏━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┓
┃ species   ┃ island    ┃ count ┃
┑━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━┩
β”‚ string    β”‚ string    β”‚ int64 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Adelie    β”‚ Torgersen β”‚    52 β”‚
β”‚ Adelie    β”‚ Biscoe    β”‚    44 β”‚
β”‚ Adelie    β”‚ Dream     β”‚    56 β”‚
β”‚ Gentoo    β”‚ Biscoe    β”‚   124 β”‚
β”‚ Chinstrap β”‚ Dream     β”‚    68 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜
>>> b = a.order_by("count")
>>> b
┏━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┓
┃ species   ┃ island    ┃ count ┃
┑━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━┩
β”‚ string    β”‚ string    β”‚ int64 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Adelie    β”‚ Biscoe    β”‚    44 β”‚
β”‚ Adelie    β”‚ Torgersen β”‚    52 β”‚
β”‚ Adelie    β”‚ Dream     β”‚    56 β”‚
β”‚ Chinstrap β”‚ Dream     β”‚    68 β”‚
β”‚ Gentoo    β”‚ Biscoe    β”‚   124 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

This allows you to combine the flexibility of Python with the scale and performance of modern SQL.

Backends

Ibis supports 20+ backends:

  • Apache DataFusion
  • Apache Druid
  • Apache Flink
  • Apache Impala
  • Apache PySpark
  • BigQuery
  • ClickHouse
  • DuckDB
  • Exasol
  • MySQL
  • Oracle
  • pandas
  • Polars
  • PostgreSQL
  • RisingWave
  • SQL Server
  • SQLite
  • Snowflake
  • Trino

How it works

Most Python dataframes are tightly coupled to their execution engine. And many databases only support SQL, with no Python API. Ibis solves this problem by providing a common API for data manipulation in Python, and compiling that API into the backend’s native language. This means you can learn a single API and use it across any supported backend (execution engine).

Ibis broadly supports two types of backend:

  1. SQL-generating backends
  2. DataFrame-generating backends

Portability

To use different backends, you can set the backend Ibis uses:

>>> ibis.set_backend("duckdb")
>>> ibis.set_backend("polars")
>>> ibis.set_backend("datafusion")

Typically, you’ll create a connection object:

>>> con = ibis.duckdb.connect()
>>> con = ibis.polars.connect()
>>> con = ibis.datafusion.connect()

And work with tables in that backend:

>>> con.list_tables()
['penguins']
>>> t = con.table("penguins")

You can also read from common file formats like CSV or Apache Parquet:

>>> t = con.read_csv("penguins.csv")
>>> t = con.read_parquet("penguins.parquet")

This allows you to iterate locally and deploy remotely by changing a single line of code.

πŸ’‘ Tip

Check out the blog on backend agnostic arrays for one example using the same code across DuckDB and BigQuery.

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 by interacting on GitHub or chatting with us on Zulip.

For more information visit https://ibis-project.org/.

Dependencies

CVE IssuesActive
0
Scorecards Score
3.90
Test Coverage
92.00%
Follows Semver
No
Github Stars
5,452
Dependenciestotal
41
DependenciesOutdated
1
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No

Learn how to distribute ibis-framework in your own private PyPI registry

pip install ibis-framework
Processing...
Done

121 Releases

PyPI on Cloudsmith

Getting started with PyPI on Cloudsmith is fast and easy.