Skip to main content

A lightweight and fun DBAPI built on pandas/csv 🎉. Supported SQL: SELECT, INSERT, UPDATE, DELETE, JOIN, GROUP BY.

Project description

🐼 Pica - Simple SQL Interface for Pandas DataFrames

Pica is a lightweight Python library that provides a SQL interface for Pandas DataFrames, following the Python DB-API 2.0 specification. It allows you to interact with your DataFrames using familiar SQL syntax while leveraging the power of Pandas under the hood.

✨ Features

  • 🔍 SQL-like interface for Pandas DataFrames
  • 📊 Supports common SQL operations
  • 🐍 Python DB-API 2.0 compliant
  • 🚀 Easy to use and integrate
  • 📝 CSV file support for persistence

🛠️ Installation

pip install pica

🎯 Quick Start

import pica
import pandas as pd

# Create a connection
conn = pica.connect()

# Register a DataFrame as a table
df = pd.DataFrame({
    'id': [1, 2, 3],
    'name': ['Alice', 'Bob', 'Charlie'],
    'age': [25, 30, 35]
})

conn.register_table('users', df, {
    'id': 'INTEGER',
    'name': 'TEXT',
    'age': 'INTEGER'
})

# Execute SQL queries
cursor = conn.cursor()
cursor.execute("SELECT name, age FROM users WHERE age > 25")
results = cursor.fetchall()
print(results)  # [('Bob', 30), ('Charlie', 35)]

🔥 Supported SQL Operations

SELECT

  • Basic SELECT with column selection
  • WHERE clause with comparison operators (=, >, <, >=, <=, !=)
  • GROUP BY with aggregate functions (COUNT, SUM, AVG, MAX, MIN)
  • ORDER BY (ASC/DESC)
  • JOIN operations
  • Aliases (AS)

Example:

SELECT name, AVG(age) as avg_age 
FROM users 
WHERE age > 25 
GROUP BY name 
ORDER BY avg_age DESC

INSERT

  • Basic INSERT INTO with VALUES

Example:

INSERT INTO users (name, age) VALUES ('David', 28)

UPDATE

  • UPDATE with WHERE clause

Example:

UPDATE users SET age = 29 WHERE name = 'Alice'

DELETE

  • DELETE with WHERE clause

Example:

DELETE FROM users WHERE age < 25

📊 Supported Data Types

  • INTEGER
  • REAL
  • BOOLEAN
  • DATE
  • TEXT

🔄 Transaction Support

conn = pica.connect()
try:
    # Perform operations
    cursor = conn.cursor()
    cursor.execute("UPDATE users SET age = 26 WHERE name = 'Alice'")
    conn.commit()
except:
    conn.rollback()
finally:
    conn.close()

📝 License

MIT License

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

pica_dbapi-0.1.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

pica_dbapi-0.1.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file pica_dbapi-0.1.0.tar.gz.

File metadata

  • Download URL: pica_dbapi-0.1.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for pica_dbapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 453620cf0772273c536872421dc89dc07cb1582e0c14969909f60aa72e80c16d
MD5 34d70928422fa9ded92597513af244a6
BLAKE2b-256 1afef3c4985d1124f0d207e94b5542e933a81f141290b8db84d3a9311d4b00ef

See more details on using hashes here.

File details

Details for the file pica_dbapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pica_dbapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for pica_dbapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13449ea94e1beb9c35c2b3399c451984529a02f7706ad986298532d10b3ab6a1
MD5 a93e0a3916049c59a2f91ada832cf5f0
BLAKE2b-256 516af53b69319347817c7cbb90b1fdd6f149e77c8f28a712de77abea8a3e89f2

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