SQL tables as first-class objects
Project description
SQLTables
SQLTables is a Python module that provides access to SQLite and PostgreSQL tables as first-class objects.
This means that tables and views can be assigned to variables and used as parameters and return values of Python functions.
Documentation: https://sqltables.readthedocs.io/
Examples are in the examples/ folder. The Machine Learning example notebook should illustrate most features.
Main Concepts and Example
The main objects are tables, represented by the Table class and associated with a Database.
New tables are created with the create_table method on the Database object.
Tables are queried with the view and table methods, which execute an SQL query and return a new Table object backed by a temporary view or table.
Within SQL queries, the special name _ refers to the table associated with self.
A simple example:
db = sqltables.Database()
rows = [["a", 1], ["b", 2], ["c", 3]]
values = db.create_table(rows=rows, column_names=["name", "val"])
values
| name | val |
|---|---|
| 'a' | 1 |
| 'b' | 2 |
| 'c' | 3 |
def square(tab):
return tab.view("select name, val, val*val as squared from _")
square(values)
| name | val | squared |
|---|---|---|
| 'a' | 1 | 1 |
| 'b' | 2 | 4 |
| 'c' | 3 | 9 |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqltables-1.8.tar.gz.
File metadata
- Download URL: sqltables-1.8.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0619a0ab16708bb43a7142a1dffc46e8c57bc944ae38221d3c52da88d5e9afde
|
|
| MD5 |
4b132ece3feac101dffc20df03442574
|
|
| BLAKE2b-256 |
4ccc979ff285c7fe0dd8ef6f103efe1b3f68ba6cf24fa23b6c23c5244ef05ff0
|
File details
Details for the file sqltables-1.8-py3-none-any.whl.
File metadata
- Download URL: sqltables-1.8-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5889904e9cd783d16c6a16350f9ef5667fa2085497dbb3527e53ef629525e26f
|
|
| MD5 |
4f7d3846f1fe2630746eefaf52071a80
|
|
| BLAKE2b-256 |
0d0eca18d005f179c9132914958025a2e4e218bf60ec909b910e15bd07fada96
|