Skip to main content

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

sqltables-1.5.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

sqltables-1.5-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file sqltables-1.5.tar.gz.

File metadata

  • Download URL: sqltables-1.5.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for sqltables-1.5.tar.gz
Algorithm Hash digest
SHA256 1ca86464815b02586b5c277bd2b0afc4c89f64b5f46dceb2335255a37b48e0a1
MD5 3f1cc21ac991db4c3aaf1211b642f164
BLAKE2b-256 99e1655d635492e64e18b36ca60f6377bb65437bb9117573216e1a1a7f6aeb3e

See more details on using hashes here.

File details

Details for the file sqltables-1.5-py3-none-any.whl.

File metadata

  • Download URL: sqltables-1.5-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for sqltables-1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 edf4974ed02f8d9ec193f927ca381406cdad0334c8aaeeb7ca051e315437f877
MD5 9f41e22a673de2ec7e97dab451446025
BLAKE2b-256 b720e63f0bb71416e55bb6dda5a38376192234f7034da65553d95b43d632e466

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page