Skip to main content

Polars expression plugin and Python extension for tokmat

Project description

tokmat-polars

Standalone Polars integration crate for tokmat.

This crate depends on the published tokmat package from crates.io and is intended to provide the dataframe-facing plugin layer around the core parser.

Rust usage

tokmat-polars can also be used directly from Rust as a normal library crate. That path is useful when you want to build Series values in Rust and reuse the same tokenization and extraction logic without going through Python.

use polars::prelude::*;
use tokmat_polars::TokmatPolars;

let plugin = TokmatPolars::from_model_path("tests/fixtures/model_1")?;
let input = Series::new("address".into(), ["123 MAIN ST"]);
let tokenized = plugin.tokenize_series(&input)?;
let extracted = plugin.extract_series(
    &tokenized,
    "<<CIVIC#>> <<STREET@+>> <<TYPE::STREETTYPE>>",
)?;
# let _ = extracted;
# Ok::<(), PolarsError>(())

Python packaging

tokmat-polars can also be built and published as a Python package via maturin. The Rust crate exposes a PyO3 extension module named tokmat_polars, and Polars can load the compiled plugin functions from that module path. Python support starts at 3.12.

Typical local workflow:

python -m venv .venv
. .venv/bin/activate
pip install -U pip maturin pytest polars
maturin develop
pytest -q

Release workflow

PyPI releases are published from GitHub Actions using Trusted Publishing. The release workflow builds wheels and an sdist on tag pushes that match v*, then uploads them through pypa/gh-action-pypi-publish. The same tag also publishes the Rust crate to crates.io using a CARGO_REGISTRY_TOKEN GitHub secret.

Release steps:

git tag v0.1.0
git push origin v0.1.0

Before the first release, configure this repository as a Trusted Publisher in the PyPI project settings and set the workflow environment to pypi if PyPI prompts for it. For crates.io, create an API token and store it in GitHub as CARGO_REGISTRY_TOKEN.

Minimal Python usage:

from pathlib import Path

import polars as pl
import tokmat_polars

plugin_path = Path(tokmat_polars.__file__).parent

expr = pl.plugins.register_plugin_function(
    plugin_path=plugin_path,
    function_name="tokenize_expr",
    args=pl.col("address"),
    kwargs={"model_path": "/path/to/model"},
    use_abs_path=True,
)

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

tokmat_polars-0.1.0.tar.gz (29.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tokmat_polars-0.1.0-cp312-cp312-win_amd64.whl (4.5 MB view details)

Uploaded CPython 3.12Windows x86-64

tokmat_polars-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

tokmat_polars-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file tokmat_polars-0.1.0.tar.gz.

File metadata

  • Download URL: tokmat_polars-0.1.0.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tokmat_polars-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ed0144cbdccd6cd6b7570d7f71731a9b9437fdac3a6a84f47af0b3ff35e3c5ff
MD5 dd510f99d8d043dde752676d2e730455
BLAKE2b-256 615a212fab047f296bbce0b22b52798b6440f54add68abd4a6306cab62dd1a52

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokmat_polars-0.1.0.tar.gz:

Publisher: release.yml on Jrakru/tokmat-polars

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokmat_polars-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for tokmat_polars-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 be4a92d3e4f846490a8be2368e33d89fb5d358d7b478a214d9b7437a1ba825a8
MD5 c71a8acad50e93df5e876ff94842320e
BLAKE2b-256 3e24172c742e461d98e07f9e676fafa2a0e2c873da3ea1e00f23c72d19405bed

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokmat_polars-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on Jrakru/tokmat-polars

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokmat_polars-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for tokmat_polars-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 259a08d81b215ee332ec84403d0ba0d5a87ff2e224135934e02f64fcf2f9104e
MD5 55f6b606a15f3083ce854c76858a3391
BLAKE2b-256 8b368286812749e897359c5ad7b3815fb051369927c477075bccde54edc97484

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokmat_polars-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: release.yml on Jrakru/tokmat-polars

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokmat_polars-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tokmat_polars-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4ae68331ff35066d8e8265e909812bef6c1db94ab4a69997b01b1a72753ba088
MD5 c48cf632b7482de2c4eb04745f974efe
BLAKE2b-256 9c5864e69bb7c354019165f0e88d3700c293dbbc92f14e84164b662a59e4517d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokmat_polars-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on Jrakru/tokmat-polars

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page