Skip to main content

gs-sql

PyPI Python 3.6, 3.7, 3.8 GitHub Pull Requests License Forks

gs-sql - this module is a Python client library for the GoogleSheetAPI data project management platform using SQL

Installation

Install the current version with PyPI:

pip install gs-sql

Or from Github:

https://github.com/EvgeniBondarev/gs-sql/archive/refs/heads/main.zip

Usage

At the first login, a browser window will open for confirmation, and a token.pickle file will be created in the directory where your credentials.json file is located to interact with the API.

from gs_sql.sheetsql import SheetsQL

gs = SheetsQL()

gs.authorization("files//credentials.json")

Afterwards, you can create a table/database in Google Sheets either using standard methods or through SQL queries.

from gs_sql.dataclasses import GsDataBase

new_base = gs.execute("""CREATE DATABASE NewBase""")

gs.connect(new_base) # or gs.connect(GsDataBase(id="1fB_1uqU8FklXAQdn9XG4QK3HG4l5U0_vvM3abQ3aiuE", name="NewBase"))

Finally, you can now create your first table.

query = gs.execute("CREATE TABLE Users (id, name)")

Final code.

from gs_sql.sheetsql import SheetsQL


gs = SheetsQL()

gs.authorization("files//credentials.json")

new_base = gs.execute("""CREATE DATABASE NewBase""")

gs.connect(new_base)

query = gs.execute("CREATE TABLE Users (id, name)")
print(query)

Available types of sql queries

DDL

No. Command Description
1 CREATE Creates a new table, view, or other object in the database
2 ALTER Modifies an existing object in the database, such as a table
3 DROP Deletes an existing table, view, or other object in the database

DML

N Command Description
1 SELECT Extracts records from one or more tables
2 INSERT Creates records
3 UPDATE Modifies records
4 DELETE Deletes records

Examples

CREATE DATABASE

gs = SheetsQL()

gs.authorization("files//credentials.json")

new_base = gs.execute("""CREATE DATABASE NewBase""")

sql.connect(new_base)

CREATE TABLE

 query = gs.execute("CREATE TABLE Users (id, name)")
 query = gs.execute("CREATE TABLE IF NOT EXISTS Users (id, name)")

ALTER TABLE

query = gs.execute("ALTER TABLE Users DROP COLUMN id;")
query = gs.execute("ALTER TABLE Users RENAME COLUMN name TO userName;")
query = gs.execute("ALTER TABLE Users ALTER COLUMN NewId, NewName;")

DROP TABLE

query = gs.execute("DROP TABLE Users;")

SELECT

query = gs.execute("SELECT * FROM tableName;")
query = gs.execute("SELECT col1, col2, ...colN FROM tableName;")
query = gs.execute("SELECT DISTINCT col1, col2, ...colN FROM tableName;")
query = gs.execute("""SELECT col1, col2, ...colN
                      FROM tableName
                      WHERE condition;""")
query = gs.execute("""SELECT col1, col2, ...colN
                      FROM tableName
                      WHERE condition1 AND|OR condition2;""")
query = gs.execute("""SELECT col2, col2, ...colN
                    FROM tableName
                    WHERE colName IN (val1, val2, ...valN);""")
query = gs.execute("""SELECT col1, col2, ...colN
                    FROM tableName
                    WHERE colName BETWEEN val1 AND val2;""")
query = gs.execute("""SELECT col1, col2, ...colN
                    FROM tableName
                    WHERE colName LIKE pattern;""")
query = gs.execute("""SELECT col1, col2, ...colN
                    FROM tableName
                    WHERE condition
                    ORDER BY colName;""")
query = gs.execute("""SELECT SUM(colName)
                    FROM tableName
                    WHERE condition
                    GROUP BY colName;""")
query = gs.execute("""SELECT COUNT(colName)
                    FROM tableName
                    WHERE condition;""")

INNER JOIN

query = gs.execute("""SELECT Orders.order_id, Orders.order_date, Customers.     customer_name
                    FROM Orders
                    INNER JOIN Customers ON Orders.customer_id = customer_id""")

INSERT INTO

query = gs.execute("""INSERT INTO table_name
                    VALUES (value1, value2, value3, ...);""")

UPDATE

query = gs.execute("""UPDATE table_name
                    SET column1 = value1, column2 = value2, ...
                    WHERE condition;""")

DELETE

query = gs.execute("""DELETE FROM table_name WHERE condition;""")

Configuration

from gs_api.sheetsql import SheetsQL
from gs_api.dataclasses import ResponseType


gs = SheetsQL()

gs.authorization("files//credentials.json")

sql.set_configuration(colum_color=[(0.85, 0.85, 0.85)], # Color in RGB format
                      response_type=ResponseType.List) # Standard List or Pandas DataFrame
```s

Metadata

Release files for gs-sql 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gs-sql 0.0.4
File Size Uploaded Provenance
gs_sql-0.0.4.tar.gz 11.3 kB Without provenance Details

Release files / gs_sql-0.0.4.tar.gz

Download URL gs_sql-0.0.4.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
64ae31dd175338432964bc36df510c514bf3e1fe9578d4a6b96163532db7886f
BLAKE2b-256 checksum
How to use checksums
dc053be591328254b62638eeb8c80f51b6344f15b1c5541df9416537dab31e44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.7

Security for gs-sql 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page