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

Uploaded Source

Built Distribution

sqltables-1.6-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqltables-1.6.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for sqltables-1.6.tar.gz
Algorithm Hash digest
SHA256 5f93c5923574b9e856ed583c9c1655d69f2b5b72a2c700acbfb9c9b45352488a
MD5 9f2a68a0c9fd357d5b05c2129a9a432c
BLAKE2b-256 7332fb39b8404104b8f28df97176e6e17ce880a05ace080dd601116474620164

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqltables-1.6-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for sqltables-1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 453e3a81e58be6cb0c348f3371c1e6285c9aac17f9d96f58f43847f02da02a3b
MD5 fdb1c37b314018e14ceef43e0e4f3335
BLAKE2b-256 80692be70092798cc7ac413884268d8ffa6bf8a1e7c783696af0295244f7e659

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