Skip to main content

Inline SQL in any Python program, on local dataframes

Project description

Inline SQL

PyPI - Version PyPI - Python Version

An engine for inline SQL in any Python program.

import pandas as pd
from inline_sql import sql


def head_data(count: int) -> pd.DataFrame:
    return sql << "SELECT * FROM 'cars.csv' LIMIT $count"


cars = head_data(50)

origin_counts = sql << """
    SELECT origin, COUNT(*) FROM $cars
    GROUP BY origin
    ORDER BY count DESC
"""
print(origin_counts)

most_common = origin_counts.origin[0]
print(sql << """
    SELECT AVG(horsepower) FROM $cars
    WHERE origin = $most_common
""")

Operates directly on an in-memory database: access local variables (pandas frames), CSV files, and interpolate values into queries.

Table of Contents

Installation

pip install inline-sql

Contributions

Contributions are appreciated, especially in the following areas:

  • Additional query engines
  • File format support (CSV, Parquet, Arrow)
  • Support for dataframe libraries (e.g., Polars)
  • Distributed computing (Ray, Dask)
  • Documentation

License

inline-sql is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inline_sql-0.0.2.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

inline_sql-0.0.2-py3-none-any.whl (3.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page