Skip to main content

Unity Catalog Pydantic

CodeQL test Python Version from PEP 621 TOML codecov

Disclaimer: This project is unofficial and not affiliated with or endorsed by the official Unity Catalog team.

Simplifies managing OSS Unity Catalog tables using Pydantic models.

Installation

pip install unitycatalog-pydantic

Examples

Create Table

from unitycatalog.client import ApiClient, TablesApi
from unitycatalog_pydantic import UCModel

class MyTable(UCModel):
    col1: str
    col2: int
    col3: float

# Initialize the API client
catalog_client = ApiClient(...)
tables_api = TablesApi(catalog_client)

# Create the table
table_info = await MyTable.create(
    tables_api=tables_api,
    catalog_name="my_catalog",
    schema_name="my_schema",
    storage_location="s3://my_bucket/my_path",
)

Retrieve Table

table_info = await MyTable.get(
    tables_api=tables_api,
    catalog_name="my_catalog",
    schema_name="my_schema",
)

Delete Table

await MyTable.delete(
    tables_api=tables_api,
    catalog_name="my_catalog",
    schema_name="my_schema",
)

Nested Models

from pydantic import BaseModel
from unitycatalog.client import ApiClient, TablesApi
from unitycatalog_pydantic import UCModel

class NestedModel(BaseModel):
    nested_col1: str
    nested_col2: int

class MyTable(UCModel):
    col1: str
    col2: NestedModel

# Initialize the API client
catalog_client = ApiClient(...)
tables_api = TablesApi(catalog_client)

# Create the table
table_info = await MyTable.create(
    tables_api=tables_api,
    catalog_name="my_catalog",
    schema_name="my_schema",
    storage_location="s3://my_bucket/my_path",
)

Using a BaseModel as root model

from pydantic import BaseModel
from unitycatalog.client import ApiClient, TablesApi
from unitycatalog_pydantic import create_table

class NestedModel(BaseModel):
    nested_col1: str
    nested_col2: int

class MyTable(BaseModel):
    col1: str
    col2: NestedModel

# Initialize the API client
catalog_client = ApiClient(...)
tables_api = TablesApi(catalog_client)

# Create the table
table_info = await create_table(
    model=MyTable,
    tables_api=tables_api,
    catalog_name="my_catalog",
    schema_name="my_schema",
    storage_location="s3://my_bucket/my_path",
)

Configuration

  • tables_api: The TablesApi client.
  • catalog_name: The catalog name.
  • schema_name: The schema name.
  • storage_location: The storage location.
  • table_type: The table type (default is TableType.EXTERNAL).
  • data_source_format: The data source format (default is DataSourceFormat.DELTA).
  • comment: A comment for the table. If not provided, the table docstring is used
  • properties: The properties of the table.
  • by_alias: Whether to use the alias or name for the columns (default is True).
  • json_schema_mode: The mode in which to generate the schema (default is validation).
  • alias: The table alias. If not provided, the class name is used.

Caveats

Tested on Parquet, Delta, and CSV data source formats. Other formats may not work as expected.

  • Currently, Parquet and Unity Catalog type integration is pretty limited. For instance, there is no way to specify the integer type, because Parquet doesn't recognize integer SQL types. The same goes for other types like DATE, TIMESTAMP, etc.. This is an integration issue and not a problem with the library itself.
  • You can't use nested models for CSV data source format. This is because CSV doesn't support nested types. This is an issue with the data source format and not the library itself.
  • Latest version of DuckDB doesn't support reading some of the required fields for UC's ColumnInfo model. e.g., precision fields. This is an integration issue and not a problem with the library itself.

Metadata

Release files for unitycatalog-pydantic 0.1.0

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

Source distribution (sdist)

Source distribution for unitycatalog-pydantic 0.1.0
File Size Uploaded
unitycatalog_pydantic-0.1.0.tar.gz 86.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for unitycatalog-pydantic 0.1.0
File Interpreter ABI Platform
unitycatalog_pydantic-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 95.4 kB

Release files / unitycatalog_pydantic-0.1.0.tar.gz

Download URL unitycatalog_pydantic-0.1.0.tar.gz
Size 86.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1e287d6e26bfe6fea7947cda9e32a13f3b8621d550927eabe83558e84ce89367
BLAKE2b-256 checksum
How to use checksums
3d4def2ad2d34b6404711e74f15ba7126d99e53f394bd29f0892d36b64921de3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 1, 2025.

Transparency log

Release files / unitycatalog_pydantic-0.1.0-py3-none-any.whl

Download URL unitycatalog_pydantic-0.1.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9cb374c8f06effe95937e869c285dddcf8ef4a4e635c1d6a332c120eea6e485f
BLAKE2b-256 checksum
How to use checksums
6f47e7fcfc2aa22311e3be771aea8e4a3e8bcbe1ddc64e794e3079f56690d167
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 1, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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