Skip to main content

DataFrame API with SQL pushdown execution and real SQL CRUD - the missing layer for SQL in Python

Project description

Moltres

CI Python 3.10+ License: MIT Documentation Status

The Missing DataFrame Layer for SQL in Python

MOLTRES: Modern Operations Layer for Transformations, Relational Execution, and SQL


Moltres combines a DataFrame API (like Pandas/Polars), SQL pushdown execution (no data loading into memory), and real SQL CRUD operations (INSERT, UPDATE, DELETE) in one unified interface.

Transform millions of rows using familiar DataFrame operations—all executed directly in SQL without materializing data.

✨ Key Features

  • 🚀 PySpark-Style DataFrame API - Primary API with 98% PySpark compatibility
  • 🗄️ SQL Pushdown Execution - All operations compile to SQL and run on your database
  • ✏️ Real SQL CRUD - INSERT, UPDATE, DELETE with DataFrame-style syntax
  • 🐼 Pandas & Polars Interfaces - Optional pandas/polars-style APIs
  • Async Support - Full async/await support for all operations
  • 🔒 Security First - Built-in SQL injection prevention
  • 🎯 Framework Integrations - FastAPI, Django, Streamlit, SQLModel, Pydantic

📦 Installation

pip install moltres

# Optional extras
pip install moltres[async-postgresql]  # Async PostgreSQL
pip install moltres[pandas,polars]     # Pandas/Polars result formats
pip install moltres[sqlmodel]          # SQLModel/Pydantic integration
pip install moltres[streamlit]        # Streamlit integration

moltres-core and pydantable

SQL execution lives in the companion moltres-core package. You can use MoltresPydantableEngine with pydantable for a typed, plan-driven API backed by SQL for supported operations. See docs/PYDANTABLE_ENGINE.md. From source, install moltres-core before moltres:

pip install -e ./moltres-core
pip install -e .

1.0.0 ships this split on PyPI: pip install moltres pulls in moltres-core automatically. For breaking changes and upgrade notes, see CHANGELOG.md.

🚀 Quick Start

from moltres import col, connect
from moltres.expressions import functions as F

# Connect to your database
db = connect("sqlite:///example.db")

# DataFrame operations with SQL pushdown (no data loading into memory)
df = (
    db.table("orders")
    .select()
    .join(db.table("customers").select(), on=[col("orders.customer_id") == col("customers.id")])
    .where(col("active") == True)
    .group_by("country")
    .agg(F.sum(col("amount")).alias("total_amount"))
)

# Execute and get results
results = df.collect()  # Returns list of dicts by default

CRUD Operations

from moltres.io.records import Records

# Insert rows
Records.from_list([
    {"id": 1, "name": "Alice", "email": "alice@example.com"},
    {"id": 2, "name": "Bob", "email": "bob@example.com"},
], database=db).insert_into("users")

# Update rows
db.update("users", where=col("active") == 0, set={"active": 1})

# Delete rows
db.delete("users", where=col("email").is_null())

📖 Documentation

Framework Integrations

🛠️ Supported Operations

DataFrame Operations: select(), where(), join(), group_by(), agg(), order_by(), limit(), distinct(), pivot(), and more

130+ Functions: Mathematical, string, date/time, aggregate, window, array, JSON, and utility functions

SQL Dialects: SQLite, PostgreSQL, MySQL, DuckDB, and any SQLAlchemy-supported database

UX Features: Enhanced SQL display (show_sql(), sql property), query plan visualization (plan_summary(), visualize_plan()), schema discovery (db.schema(), db.tables()), query validation (validate()), performance hints (performance_hints()), and interactive help (help(), suggest_next())

🧪 Development

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Code quality
ruff check . && ruff format . && mypy src

🤝 Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

📄 License

MIT License - see LICENSE file for details.


Made with ❤️ for the Python data community

⬆ Back to Top

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

moltres-1.0.0.tar.gz (378.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moltres-1.0.0-py3-none-any.whl (462.6 kB view details)

Uploaded Python 3

File details

Details for the file moltres-1.0.0.tar.gz.

File metadata

  • Download URL: moltres-1.0.0.tar.gz
  • Upload date:
  • Size: 378.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for moltres-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fbf44e55de73bfbec35165d886da52ef17b28acc69e6eb090fe933723f6ae90e
MD5 dd999edb0dbf181a7384b7bf34b2f786
BLAKE2b-256 8673510e3036e50a2ea2362cb8f2dc4f980dbf79308fe54d973b75218bab306a

See more details on using hashes here.

File details

Details for the file moltres-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: moltres-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 462.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for moltres-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35ac5520ae6b59ed3b19cf090199abdefe7b17b7697f2ba778ad157b8ac30fee
MD5 22e694715f4f7157b93a91bf2ad44fa3
BLAKE2b-256 a5471058ec4e8f9ef1d9e0450d56721a00da329587194e6c0ffb48561df6d02e

See more details on using hashes here.

Supported by

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