Skip to content

CLI Tool

The snowman command is provided to assist in the integration between Snowflake and Python.

Initialization

$ snowman init

Initialize Snowman configuration. For more information on configuration items, please read Configuration.

Tip

Initialize the snowman.toml file or set [tool.snowman] in pyproject.toml with the --file option. By default, the pyproject.toml file is created.

Example

snowman init

Python Model Generator

$ snowman model generate

Automatically generate Pydantic models from Snowflake information schemas.

Example

snowman model generate
Generated Code

Source: Snowflake

CREATE TABLE DATABASE.SCHEMA.USER (
    ID INTEGER NOT NULL COMMENT 'User ID',
    NAME TEXT NOT NULL COMMENT 'User Name',
    AGE INTEGER DEFAULT NULL COMMENT 'User Age',
    CREATED_AT TIMESTAMP_TZ NOT NULL DEFAULT CURRENT_TIMESTAMP() COMMENT 'Created At'
) COMMENT 'User Table';

Output: Python Code

#
# Code generated by snowman; DO NOT EDIT.
#
# For more information about snowman,
# please refer to https://github.com/yassun7010/snowman-py .
#

import datetime
import typing

import pydantic
import snowman

if typing.TYPE_CHECKING:
    from . import _schema as _schema


# TABLE: DATABASE.SCHEMA.USER
@snowman.table("DATABASE", "SCHEMA", "USER")
class User(
    snowman.Table[
        "User",
        "_schema._UserColumnAccessor",
        "_schema._UserOrderItemAccessor",
        "_schema._UserInsertTypedDict",
        "_schema._UserUpdateTypedDict",
    ]
):
    """User Table"""

    id: typing.Annotated[
        snowman.datatype.INTEGER, pydantic.Field(title="User ID", alias="ID")
    ]
    """User ID"""

    name: typing.Annotated[
        snowman.datatype.TEXT, pydantic.Field(title="User Name", alias="NAME")
    ]
    """User Name"""

    age: typing.Annotated[
        snowman.datatype.INTEGER | None, pydantic.Field(title="User Age", alias="AGE")
    ] = None
    """User Age"""

    created_at: typing.Annotated[
        snowman.datatype.TIMESTAMP_TZ,
        pydantic.Field(title="Created At", alias="CREATED_AT"),
    ] = snowman.pydantic.DefaultFactory(datetime.datetime.now)
    """Created At"""

$ snowman model diff

Check differences between Python models and Snowflake information schemas.

Example

snowman model diff --check