Databricks helpers for Pydantic models
Project description
Pydantic Databricks
Overview
This library leverages Pydantic to simplify the generation of Databricks SQL queries for managing tables. It provides a convenient way to define table schemas using Pydantic models and generates corresponding SQL statements.
Installation
pip install pydantic-databricks
Usage
1. Basic Example Table Creation
from pydantic_databricks.models import DatabricksModel
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
class Schema(DatabricksModel):
_table_name = "test"
_schema_name = "test_schema"
col1: str
col2: int
col3: float
spark.sql(Schema.create_table())
Generated SQL:
CREATE TABLE test_schema.test (col1 STRING, col2 BIGINT, col3 DOUBLE) USING DELTA;
Currently Supported Options
_catalog_name
: The catalog name for the table. Default isNone
. IfNone
then a two part namespace is used._schema_name
: The schema name for the table (required)._table_name
: The name of the table (required)._grants
: A set of Grant objects. Default isNone
._location_prefix
: The location prefix for external tables. Default isNone
. If set, then the table is created as an external table._table_properties
: A dictionary of table properties._table_create_mode
: The mode for table creation. Default isCreateMode.CREATE
._table_data_source
: The data source for the table. Default isDataSource.DELTA
._partition_columns
: A list of partition columns for the table. Default isNone
._options
: A dictionary of additional options for table creation. Default isNone
._comment
: A comment for the table. Default isNone
.
Coming soon
- Support for table and column constraints
- Support for creating grant statements
Contributing
We welcome contributions to pydantic-databricks! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a branch for your feature or bug fix.
- Make your changes.
- Test your changes thoroughly.
- Submit a pull request.
License
- pydantic-databricks is licensed under the MIT License. See LICENSE for more information
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pydantic_databricks-0.1.0.tar.gz
.
File metadata
- Download URL: pydantic_databricks-0.1.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.10.4 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53bdf3df1824157a7bf8fad0dcbd4563eb979373e842cefc1eda48303d61bc25 |
|
MD5 | 7969ad7b529f97e5784cb7be9d85e413 |
|
BLAKE2b-256 | 613e5942b7a5844d0a5da52901cb05995e6100cbcdc1bb023c0f8615c5e646bb |
File details
Details for the file pydantic_databricks-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pydantic_databricks-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.10.4 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ff1a5771de089a615deb593141292a3070684b1a7c47595485ff0a0da6f1413 |
|
MD5 | 4173f8e4de5fbe831c40de0e167fc509 |
|
BLAKE2b-256 | 58387822c8ed497d36007af237cf38fb9a5d9903c0883ee675876d14282d599f |