Skip to main content

SQL-like interface to tabular structured data

Project description

tSQLike

SQL-like interface to tabular structured data

Still in development: beware of bugs, every API entry is a subject to change

Description

tSQLike is a Python3 module that is written with a hope to make tabular data process easier using SQL-like primitives.

Usage

from tsqlike import tsqlike

t1 = tsqlike.Table(data=[['h1', 'h2', 'h3', 'h4'],
                        ['a', 'b', 'c', 'd'],
                        ['b', 'c', 'd', 'd'],
                        ['f', 'g', 'h', 'i']],
                  name='first')
t2 = tsqlike.Table().import_list_dicts(data=[{'h1': 1, 'h2': 2, 'h3': 3},
                                            {'h1': 'd', 'h2': 'e', 'h3': 'f'}],
                                       name='second')
t3 = t1.join(t2, on='first.h4 == second.h1').select('*').order_by('second.h2', direction=tsqlike.ORDER_BY_DEC)
t3.write_csv(dialect='unix')

"first.h1", "first.h2", "first.h3", "first.h4", "second.h1", "second.h2", "second.h3"
"b", "c", "d", "d", "d", "e", "f"
"a", "b", "c", "d", "d", "e", "f"

Functionality

Table class

The main class of the module

Data processing methods

Name Status Description
join Join two Tables (self and table) on an expression *
join_lt Light, limited and safe Join, that doesn't use eval()
select Select column(s) from the Table *
select_lt eval()-free version of select
order_by ORDER BY primitive of SQL SELECT to sort the Table by a column
group_by GROUP BY primitive of SQL SELECT to apply aggregate function on a column

Import methods

Name Status Description
import_dict_lists Import a dictionary of lists into Table object
import_list_dicts Import a list of horizontal arranged dictionaries into the Table
import_list_lists Import list(list_1(), list_n()) with optional first row as the header

Read methods

Name Status Description
read_json Read JSON structure
read_csv Read CSV file
read_xml Read XML. NB: Do we need XML support?

Export methods

Name Status Description
export_dict_lists Export a dictionary of lists
export_list_dicts Export list of dictionaries
export_list_lists Export list(list_1(), list_n()) with optional first row as the header

Write methods

Name Status Description
write_csv Make CSV from the Table object and write it to a file or stdout
write_json Write JSON into file or STDOUT *
write_json_lr eval()-free version of Table.write_json
write_xml Write XML. NB: Do we need this?

Private methods

Name Status Description
_redimension Recalculate dimensions of the Table.table

EvalCtrl class

Controls what arguments are available to eval() function

Name Status Description
blacklisted Checks if there is any of the blacklised words in stanza
blacklist_add Add a new word into the black list
blacklist_remove Remove the word from the blacklist

Standalone functions

Name Status Description
open_file Open a file
close_file Close a file

WARNING!

Methods Table.join(on=), Table.select(where=) and Table.write_json(export_f=), use eval() function to run specified expressions within the program. ANY expression, including one that is potentially DANGEROUS from security point of view, can be passed as the values of the above arguments. It is your duty to ensure correctness and safety of these arguments and EvalCtrl helps to block potentially dangerous function/method names.

Alternatively you can use Table.join_lt(), Table.select_lt() and Table.write_json(). They are significantly less powerful, but do not use eval().

Installation

pip install tsqlike

Contacts

If you have an idea, a question, or have found a problem, do not hesitate to open an issue or mail me directly: Mikhail Zakharov zmey20000@yahoo.com

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

tsqlike-1.0.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

tsqlike-1.0.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file tsqlike-1.0.1.tar.gz.

File metadata

  • Download URL: tsqlike-1.0.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.4

File hashes

Hashes for tsqlike-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8a7155f50203b08be8a5f9231180e9309dac88dc4e76439579db16f56482d59f
MD5 f50fc9c14fda8ff8c597a52ef872b35b
BLAKE2b-256 23255b27715858c9d0bd0eac373305ccb0186959da949b68e6db7fe0c2dd8cd2

See more details on using hashes here.

File details

Details for the file tsqlike-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: tsqlike-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.4

File hashes

Hashes for tsqlike-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0540afddca51ddb844c1082a4cbf7b29869f3fecd4cec9031b1e95bc0679263
MD5 231b149d0f6dc95eee2b880bb3155c48
BLAKE2b-256 3d58bc418ae74d339a37274f793442b1e6a1f2ae2773916725e75e16634497b0

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