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.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

sqltables-1.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqltables-1.3.tar.gz
  • Upload date:
  • Size: 7.4 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.6

File hashes

Hashes for sqltables-1.3.tar.gz
Algorithm Hash digest
SHA256 a3b3296a7720470be311093cd7fc1a139ab4dbcbbcccd9f464a77f1663abda3a
MD5 b1e2293bd6afdfee3868e12616dcb528
BLAKE2b-256 6237d5db100f7becf6ae223ffe9e9137012ce7beeaf650e9466c58e2c2f851cd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqltables-1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 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.6

File hashes

Hashes for sqltables-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 28890d875195572e1f68c3fde6b79eaf7672b83a4177f96b41fdce7fa0e25429
MD5 2b68182c5a17ca17ef2daf491cdc5e83
BLAKE2b-256 6ed4b3d4e4fb0317457e9426e28303c9cf9c8d919036a8cb978af82cddee39d4

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