Databricks SQL
Databricks SQL framework, easy to learn, fast to code, ready for production.
Installation
$ pip install databricks-sql
Configuration
from databricks_sql.client import Configuration
CONFIGURATION = Configuration.instance(
access_token="",
command_directory="",
http_path="",
server_hostname="",
)
Usage
Databricks SQL usage description:
Delete
Delete with where
from databricks_sql.client import Database
with Database() as connection:
(
connection
.delete("catalog.schema.table")
.where("id", "994238a4-8c18-436a-8c06-29ec89c4c056")
.execute()
)
Delete with where condition
from databricks_sql.client import Database
with Database() as connection:
(
connection
.delete("catalog.schema.table")
.where("description", "%Databricks%", operator="LIKE")
.execute()
)
Execute
from databricks_sql.client import Database
with Database() as connection:
(
connection
.execute(
"""
CREATE TABLE IF NOT EXISTS catalog.schema.table (
id STRING NOT NULL,
name STRING NOT NULL,
description STRING,
CONSTRAINT table_primary_key PRIMARY KEY(id)
) USING DELTA
""",
parameters=None,
skip_load=True,
)
)
Insert
from databricks_sql.client import Database
with Database() as connection:
(
connection
.insert("catalog.schema.table")
.set("id", "994238a4-8c18-436a-8c06-29ec89c4c056")
.set("name", "Name")
.set("description", "Description")
.execute()
)
Paging
Paging with where condition
from databricks_sql.client import Database
with Database() as connection:
(
connection
.select("catalog.schema.table")
.fields("id", "name", "description")
.where("name", "%Databricks%", operator="LIKE")
.order_by("id")
.paging(0, 10)
)
Paging without where condition
from databricks_sql.client import Database
with Database() as connection:
(
connection
.select("catalog.schema.table")
.paging(0, 10)
)
Select
Fetch all
from databricks_sql.client import Database
with Database() as connection:
(
connection
.select("catalog.schema.table")
.execute()
.fetch_all()
)
Fetch many
from databricks_sql.client import Database
with Database() as connection:
(
connection
.select("catalog.schema.table")
.execute()
.fetch_many(1)
)
Fetch one
from databricks_sql.client import Database
with Database() as connection:
(
connection
.select("catalog.schema.table")
.execute()
.fetch_one()
)
Select by file
from databricks_sql.client import Database
with Database() as connection:
(
connection
.execute("command.sql", {"id": "994238a4-8c18-436a-8c06-29ec89c4c056"})
.fetch_one()
)
Select by command
from databricks_sql.client import Database
with Database() as connection:
(
connection
.execute("SELECT id, name, description FROM catalog.schema.table WHERE id = %(id)s", {"id": "994238a4-8c18-436a-8c06-29ec89c4c056"})
.fetch_one()
)
Update
Update with where
from databricks_sql.client import Database
with Database() as connection:
(
connection
.update("catalog.schema.table")
.set("name", "New Name")
.set("description", "New Description")
.where("id", "994238a4-8c18-436a-8c06-29ec89c4c056")
.execute()
)
Update with where all
from databricks_sql.client import Database
with Database() as connection:
(
connection
.update("catalog.schema.table")
.set("name", "New Name")
.set("description", "New Description")
.where_all({"id": "994238a4-8c18-436a-8c06-29ec89c4c056", "name": "Name", "description": "Description"})
.execute()
)
Using mustache
SQL
select
id,
name,
description
from catalog.schema.table
where 1 = 1
{{#id}}
and id = %(id)s
{{/id}}
{{#name}}
and name like %(name)s
{{/name}}
Select with filters
from databricks_sql.client import Database
with Database() as connection:
(
connection
.execute("command.sql", parameters={"id": "994238a4-8c18-436a-8c06-29ec89c4c056", "name": "Name"})
.fetch_one()
)
License
This project is licensed under the terms of the Apache License 2.0.
Metadata
Release files for databricks-sql 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| databricks_sql-1.0.0.tar.gz | 8.6 kB | Without provenance | Details for databricks_sql-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| databricks_sql-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for databricks_sql-1.0.0-py3-none-any.whl |
Total release size: 17.3 kB
Release files / databricks_sql-1.0.0.tar.gz
| Download URL | databricks_sql-1.0.0.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3817b209fcb4b840b4287fe9bc5e90081178a70c89b5fa2dd58a226c7305adc7
|
|
BLAKE2b-256 checksum How to use checksums |
85a0b89bf51cadbf67913a33a0258b1362b7ca6cf526adfb465641916e62a0ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.8.15 Linux/5.15.0-1023-azure
|
Release files / databricks_sql-1.0.0-py3-none-any.whl
| Download URL | databricks_sql-1.0.0-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4693df00703e05c00eae4e0355a738d41f571fa93658ad22eb9f30e80299f446
|
|
BLAKE2b-256 checksum How to use checksums |
86c0ad5be27199d32e3de59478358a6939dd250f1c9c4e220b69d210e1159593
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.8.15 Linux/5.15.0-1023-azure
|
Security for databricks-sql 1.0.0
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.