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.
Motivation
Relational data schemas are a proven way of organizing data, that fit the majority of query and processing use cases.
SQL is a powerful query language, that generally maintains high readability and is familiar to most people working with data.
SQLite is a powerful relational database, part of the Python standard library, that supports both in-memory and out-of-memory processing.
The goal of this module is to provide a high performance relational data structure that integrates seamlessly with Python's features for structuring programs, such as control flow constructs, functions or classes.
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
File details
Details for the file sqltables-1.2.tar.gz
.
File metadata
- Download URL: sqltables-1.2.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90be2db38a9e8348cf28b466f404933d03d4f1b58151dbbc9e74600c5087a9d3 |
|
MD5 | f69c8a02846cf2dab6f85dfd697120fe |
|
BLAKE2b-256 | 43818f7ab8eada9d21d555fa0631b3d73fabbb46b7c02b511f95e290a06a2b3c |
File details
Details for the file sqltables-1.2-py3-none-any.whl
.
File metadata
- Download URL: sqltables-1.2-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c82c5ee53e4c1b8710ddabca4f1f82363d3518af75a0b5a605250168033ada5b |
|
MD5 | d81d3714c5405d99002551649ff838ea |
|
BLAKE2b-256 | 5e593fb9ca09bdb7f3e22f5358bfc9c0f732517280f7114d0531d2a7ad3db2a2 |