Skip to main content

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 is None. If None 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 is None.
  • _location_prefix: The location prefix for external tables. Default is None. 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 is CreateMode.CREATE.
  • _table_data_source: The data source for the table. Default is DataSource.DELTA.
  • _partition_columns: A list of partition columns for the table. Default is None.
  • _options: A dictionary of additional options for table creation. Default is None.
  • _comment: A comment for the table. Default is None.

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:

  1. Fork the repository.
  2. Create a branch for your feature or bug fix.
  3. Make your changes.
  4. Test your changes thoroughly.
  5. Submit a pull request.

License

  • pydantic-databricks is licensed under the MIT License. See LICENSE for more information

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

pydantic_databricks-0.2.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

pydantic_databricks-0.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_databricks-0.2.0.tar.gz.

File metadata

  • Download URL: pydantic_databricks-0.2.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.10.4 CPython/3.12.0

File hashes

Hashes for pydantic_databricks-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e70029821abd776873caaadb639b0ee72733c00572dcd23d4dc911d021f507ad
MD5 3157773ad44374ca911f8c271663d203
BLAKE2b-256 e462f167e7d1754dc1f237156ed452a611dc4de30a3f5c210e640d59036eb568

See more details on using hashes here.

File details

Details for the file pydantic_databricks-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_databricks-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77d14d7208ad37bf495c1f9195dfd422922bc7fc19e12d733d5fb1ed47738bc1
MD5 0ccc3dde0d0bea0cbc7e8f31e9a59746
BLAKE2b-256 7a9adf6c6590ea615fa15d8e0b8caf23d519c95df078ba0017feb995ebbda927

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