Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

sqlmeshsm [EXPERIMENTAL]

PyPI version License: MIT python codecov

SQLMesh macros used for ❄️ Dynamic Masking Policies Implementation ✏️

List of macros 🚧 (currently blocked by awaiting for more supports from the sqlmesh's Macro Context)

  • create_masking_policy (source)
  • apply_masking_policy (source)

And, the Snowflake Hooker CLI (hook) ⭐

Hooks ✅

  • hook drop_masking_policy -c {config.yml} -mp {func}

Data Masking Development

1. Installation

pip install sqlmeshsm --upgrade

In your (sqlmesh-project-dir)/macros/__init__.py, let's import our lib:

from sqlmeshsm import macros

2. Create masking policy functions

For example, the customer table needs the following masking policies:

  • First Name: mask with * except the first 3 characters, fixed length of 10, no masking of null
  • Last Name: mask with the first character of Full Name, no masking of null

There are 2 masking functions, they must be created with following requirements:

  • 📂 Files located under (your-sqlmesh-project)/macros/snow-mask-ddl
  • 🆎 File name format: {mp_schema}.{mp_function_name}
-- /snow-mask-ddl/mp_schema.mp_first_name.sql
CREATE MASKING POLICY IF NOT EXISTS @schema.mp_first_name AS (
    masked_column string
) RETURNS string ->
    LEFT(CASE
        WHEN masked_column IS NOT NULL THEN LEFT(masked_column, 3)
        ELSE NULL
    END || '**********', 10);
-- /snow-mask-ddl/mp_schema.mp_last_name.sql
CREATE MASKING POLICY IF NOT EXISTS @schema.mp_last_name AS (
    masked_column string,
    full_name_column string
) RETURNS string ->
    CASE
        WHEN masked_column IS NOT NULL THEN LEFT(full_name_column, 1)
        ELSE NULL
    END;

@schema is the keyword to indicate the schema name which matches to the first part of the file name

3. Decide to mask model's columns

/* /models/my_customer_model.sql */
MODEL(
    name my_schema.my_customer_model
    kind FULL
    ...
)

/* MODEL SQL CODE HERE */

/* OPTIONAL, ADD this if mp_schema schema is not part of any models */
CREATE SCHEMA IF NOT EXISTS mp_schema;

/* REGISTER the masking funcs */
@create_masking_policy(mp_schema.mp_first_name)
@create_masking_policy(mp_schema.mp_last_name)

/* USE the masking funcs */
@apply_masking_policy(first_name, mp_schema.mp_first_name)
@apply_masking_policy(my_schema.my_customer_model, last_name, mp_schema.mp_last_name, ['full_name'])

Let's plan and apply it now: sqlmesh plan --select-model my_schema.my_customer_model

4. (Optional) Decide to clean up the masking policies

Let's run the built-in hooks:

hook drop_masking_policy -c /path/to/sqlmesh/config.yml -mp you_mp_function_name
# for example: hook drop_masking_policy -c C:\Users\DAT\.sqlmesh\config.yml -mp common.mp_first_name

Try hook -h for more options.

Voila! Happy Masking 🎉

Contribution

buy me a coffee

If you've ever wanted to contribute to this tool, and a great cause, now is your chance!

See the contributing docs CONTRIBUTING for more information.

Our Contributors:

Metadata

Release files for sqlmeshsm 0.1.0b5

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

Source distribution (sdist)

Source distribution for sqlmeshsm 0.1.0b5
File Size Uploaded Provenance
sqlmeshsm-0.1.0b5.tar.gz 8.5 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 20.8 kB

Release files / sqlmeshsm-0.1.0b5.tar.gz

Download URL sqlmeshsm-0.1.0b5.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7f17d5cfca31fa12c9c87ea5cdc3bcac7e9abc9b8d1e3d044d9937dee5a8b468
BLAKE2b-256 checksum
How to use checksums
cf9d4bbb765b3e36307541186f2dfe61b55955366f07bb285fe4bf20a68048c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.5 Linux/6.2.0-1011-azure

Release files / sqlmeshsm-0.1.0b5-py3-none-any.whl

Download URL sqlmeshsm-0.1.0b5-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd0ad281b725c1449d648e3a1a6e9e1298a024d8c50c0ed79682d0373f7a74b6
BLAKE2b-256 checksum
How to use checksums
f015583cead505a9b678a107f91c559de30fd26f9498b98206f546d88301ab3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.5 Linux/6.2.0-1011-azure

Security for sqlmeshsm 0.1.0b5

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.

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