SQLite tables as first-class objects
Project description
SQLTables
SQLTables is a Python module that provides access to SQLite 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 load_values
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.load_values(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.1.tar.gz
.
File metadata
- Download URL: sqltables-1.1.tar.gz
- Upload date:
- Size: 5.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 | e5f1e989fb7a47ea69cebc899692d5e5c48cea5126317fd962cdd27fedf89093 |
|
MD5 | b4688b7bd8499242adbafd01346989cb |
|
BLAKE2b-256 | 15822c92d40eed826da30d3b75b3a9ccf2310a09f87612ee00b16b769337d66f |
File details
Details for the file sqltables-1.1-py3-none-any.whl
.
File metadata
- Download URL: sqltables-1.1-py3-none-any.whl
- Upload date:
- Size: 6.1 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 | b3adcf36e9a6684708c5bca3eaadf466207fb27aad0bd9a4ead89f4a28a88402 |
|
MD5 | 1a589d6cc39c9f29d68b062b097f5c50 |
|
BLAKE2b-256 | 7f69528cba57b07ebb3c715b63d9437047429b795ccd12aee44f2d7fd07407e1 |