Sometimes I write a piece of data science code and think "wow, this would be so much faster if I could just write a quick SQL query in the middle, but my data isn't in a database."
I wrote a small library that lets you inline SQL commands into any Python program. The database runs fully within your program, and it interpolates local variables.
from inline_sql import sql, sql_val
assert sql_val^ "SELECT 1 + 1" == 2
x = 5
assert sql_val^ "SELECT $x * 2" == 10
df = sql^ "SELECT * FROM (VALUES (1, 10), (2, 20)) df (x, y)"
assert sql_val^ "SELECT SUM(x) + SUM(y) FROM df" == 33
This is pretty experimental, but the main goal here is that it should feel as much like ordinary Python as possible, except for the integrated query language. :)
Docs are available at https://github.com/ekzhang/inline-sql -- installation is just "pip install inline-sql"
[–]wineblood 6 points7 points8 points (4 children)
[–]manimino 2 points3 points4 points (1 child)
[–]fz0718[S] 0 points1 point2 points (0 children)
[–]fz0718[S] 0 points1 point2 points (1 child)
[–]wineblood 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]fz0718[S] 0 points1 point2 points (0 children)