Skip to main content

Python bindings and helpers for finite metric-space numerics

Project description

METRIC Python Package

Python bindings for METRIC metric-space numerics.

The public Python distribution name is mtrc. The import package remains metric.

The revived core package exposes the project concepts explicitly:

  • metric.metrics: metric constructors such as Edit
  • metric.Space: minimal intent-first finite metric space facade
  • metric.spaces: finite metric-space helpers such as FiniteMetricSpace
  • metric.operators: pairwise-distance, nearest-neighbor, range-neighbor, exact graph-result, graph-connectivity-diagnostics, graph-degree-diagnostics, graph-stretch-diagnostics, graph-symmetrization, graph-out-degree-pruning, exact graph-edge, representative-selection, medoid, separated-representative, and radius-coverage helpers
  • metric.mappings: beta compatibility bridge for installed mapping bindings
  • metric.transforms: beta compatibility bridge for installed transform bindings

The same objects are also available as convenience imports from metric for short examples.

Installation

The Python package is in revival. The current supported CPython targets for the core wheel are 3.10, 3.11, 3.12, 3.13, and 3.14.

After the package is published to PyPI, install the core package with:

python -m pip install mtrc

Until PyPI publishing is completed, build from source with the instructions below.

Packaging now uses pyproject.toml with isolated PEP 517 builds and PEP 621 project metadata. setup.py provides the CMake extension build hook and the source-distribution hook that carries the required C++ headers into the Python sdist. The build prefers the pybind11 package from the build environment (pybind11>=3.0.0) and falls back to a current FetchContent copy when no CMake package is available.

CI builds core wheel artifacts for Linux, macOS, and Windows across the supported CPython versions.

Build from the source

git clone --recurse-submodules https://github.com/metric-space-ai/metric

Install Prerequisites

Ubuntu

sudo apt-get install cmake
sudo apt-get install libboost-all-dev

OpenBLAS or another BLAS implementation is optional for the revived core wheel. It can improve broader linear-algebra paths, but the CI core wheel builds with METRIC_PYTHON_USE_BLAS=OFF.

Windows

Install Miniconda. In Conda CLI initialize your virtual environment with desired Python version:

conda create --name my_env -y python=3.12
conda activate my_env

OpenBLAS is optional for the revived core wheel. For legacy full bindings or broader linear-algebra paths, install it from conda-forge:

conda config --add channels conda-forge
conda update -n base conda -y
conda install -c conda-forge libopenblas openblas -y

Build package

At least 2GB of RAM is required

python -m pip wheel . --no-deps -w dist

By default this builds the revived core bindings. At this stage the default wheel exposes the Edit distance binding, space bindings, transform bindings, and the pure Python package surface. The legacy standard-distance, utils, mapping, and correlation bindings still require restoration and can be attempted with:

CMAKE_COMMON_VARIABLES="-DMETRIC_PYTHON_BUILD_FULL=ON" python -m pip wheel . --no-deps -w dist

To force the portable core-wheel mode used by CI:

CMAKE_COMMON_VARIABLES="-DMETRIC_PYTHON_USE_BLAS=OFF" python -m pip wheel . --no-deps -w dist

Install module

python -m pip install dist/*

Examples

from metric import Edit, Space

records = ["cat", "cot", "coat", "dog"]
space = Space(records, Edit())

print("distance(cat, cot) =", space(0, 1))
print("nearest:", space.neighbors("cut", 2))

The core-wheel example is also available at examples/metric_space/string_edit_space.py. Full correlation, mapping, and standard-distance examples remain part of the broader restoration path until their bindings are promoted into the default wheel.

Small tutorial notebooks live under notebooks/. They are paired with notebooks/smoke_notebooks.py, which executes their code cells in CI after the wheel is installed.

metric.mappings and metric.transforms are importable beta namespaces. They expose available() and legacy_module() so callers can inspect whether a wheel includes the broader legacy bindings without making those bindings part of the core-wheel contract.

NumPy records

The revived Python facade treats NumPy rows as records when the metric callable accepts them:

import numpy as np
from metric import Space

records = np.array([[0.0, 0.0], [3.0, 4.0], [6.0, 8.0]])
space = Space(records, lambda lhs, rhs: float(np.linalg.norm(lhs - rhs)))
print(space.distance(0, 1))

Pairwise distance helpers return Python lists of lists; call np.asarray(...) if an ndarray result is required.

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

mtrc-0.3.4.tar.gz (415.1 kB view details)

Uploaded Source

Built Distributions

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

mtrc-0.3.4-cp314-cp314-win_amd64.whl (685.3 kB view details)

Uploaded CPython 3.14Windows x86-64

mtrc-0.3.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (494.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

mtrc-0.3.4-cp314-cp314-macosx_11_0_arm64.whl (398.1 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

mtrc-0.3.4-cp313-cp313-win_amd64.whl (666.2 kB view details)

Uploaded CPython 3.13Windows x86-64

mtrc-0.3.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (494.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

mtrc-0.3.4-cp313-cp313-macosx_11_0_arm64.whl (397.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

mtrc-0.3.4-cp312-cp312-win_amd64.whl (666.1 kB view details)

Uploaded CPython 3.12Windows x86-64

mtrc-0.3.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (494.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

mtrc-0.3.4-cp312-cp312-macosx_11_0_arm64.whl (396.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

mtrc-0.3.4-cp311-cp311-win_amd64.whl (656.8 kB view details)

Uploaded CPython 3.11Windows x86-64

mtrc-0.3.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (490.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

mtrc-0.3.4-cp311-cp311-macosx_11_0_arm64.whl (396.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

mtrc-0.3.4-cp310-cp310-win_amd64.whl (653.9 kB view details)

Uploaded CPython 3.10Windows x86-64

mtrc-0.3.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (484.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

mtrc-0.3.4-cp310-cp310-macosx_11_0_arm64.whl (391.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file mtrc-0.3.4.tar.gz.

File metadata

  • Download URL: mtrc-0.3.4.tar.gz
  • Upload date:
  • Size: 415.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4.tar.gz
Algorithm Hash digest
SHA256 bdbdecabefb6b0908d312aa1a9a2971c3435ef6bb823ad692970174472cf2761
MD5 3033b5cadf9512e5caa457958ae52bb3
BLAKE2b-256 5c9959bc1cf5f92af3361d97571e1120444a5198a74579c7bd5a12fe9a22834b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4.tar.gz:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: mtrc-0.3.4-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 685.3 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 787cd8715c284ee3afc3bfeb93e1b397d7009ebf10ad51d2731a2b4603bb5e68
MD5 175b69737b2291f7dd9e5758920a82b5
BLAKE2b-256 82a19cf1398801de07b82302e2ffe5fa1bcd7ca25ddf8a2d93e12f53e41c0751

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp314-cp314-win_amd64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mtrc-0.3.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d547a9f8610c941fbf4486e652fa09d979860219014ed078415474c56e6e99c8
MD5 8aa68fa5553d55e44f46e78ed5d0e0aa
BLAKE2b-256 a08445af9d4c5f81a22999f52740f664792d5db35a4de5c45c362e71da4d41b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

  • Download URL: mtrc-0.3.4-cp314-cp314-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 398.1 kB
  • Tags: CPython 3.14, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5503483fc223ae8628a128b47fc1ceb9dd5065bbb7a2a3d067cffb94bbe025fd
MD5 d031df22df26d782f76862641df8c07a
BLAKE2b-256 51beeff5f33cf5e141ccacd74d19b5b37d9710f8b1d1c1a5dfaf690c776697d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: mtrc-0.3.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 666.2 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 313d722982af9934b3c78eabde4904d854e322cdd15c6409bba02556dd7d7924
MD5 bda1249e6294ec00bf05e3aea7308063
BLAKE2b-256 e37132d384a8edc5420af57ed21f90ca4bad3937126e24d657d27f5c54f4274d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp313-cp313-win_amd64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mtrc-0.3.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 732fc78a2fde1f0f8f467489d68cdc58039a4b9463dcc5001bc60cd4ef93f541
MD5 a306ec306d5175d5eb3baf0a11fd31eb
BLAKE2b-256 6a84054f577a75e332121a339a63467db7777cda002695558c8160e437474edb

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

  • Download URL: mtrc-0.3.4-cp313-cp313-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 397.0 kB
  • Tags: CPython 3.13, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5dbe42d6a6eb2deb8c318b0b798eeed8051b4792c4a18ac5b83ad79fb81aff49
MD5 ef6f51aecf6a4ade9aaf694c2e342459
BLAKE2b-256 28955248f0571e64768164c9a56360ff089eca737760dcbae6097a84b6ed45a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: mtrc-0.3.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 666.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 896ac709ee0390a557006079175a90c1b68e8986477adc0c2cb84204db2984e0
MD5 161a0b44e436586222176ea7dd73c5b1
BLAKE2b-256 52c5a3d08fd63289ec94a3d437130ad5cafbe38f4ab9197602d839086be05b0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp312-cp312-win_amd64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mtrc-0.3.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9dde519d3eb72b5ff0ff773c80343a0ad3db4d06edb3db684fc0ec6793ca547e
MD5 b0088cc928ce11b3bfef7837d078ddcc
BLAKE2b-256 2ed84d54849b3d60afa210e00d11cfea16c38d7c292cf9e71c717c602c3e80c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

  • Download URL: mtrc-0.3.4-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 396.8 kB
  • Tags: CPython 3.12, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e80d7f78c135bf51a4786225495b6e10bac68d177a6ab63471db68f6c5f41b22
MD5 f10feb83dcc965e82b268c6e2244cfd9
BLAKE2b-256 7846e675fcdc2c8acd8f6ac2fd2ecf7a6fbab039b1d9d6099097c2eb15261f6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: mtrc-0.3.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 656.8 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 08e6aa72e3b7c3d4cef33ea4f605704e43c4bdf445bf18b73027ac11f1697ccb
MD5 b0ee1580b26da6909640feae6bbbf0df
BLAKE2b-256 142675d892628f11895f1569ee9cf206cde9aef1169cceb9b46c75df1cd3635b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp311-cp311-win_amd64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mtrc-0.3.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2b52bc5788a1a47d17cc2c12b8d3ee2446518ef773f4a977e593c2a22b75f834
MD5 1e4a77a4d54a2f7634793d696d4eb6c7
BLAKE2b-256 b39fa72c0cf743e3e77acee32a8773bee61a80d9f6568b46b7cc104c9e80038b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

  • Download URL: mtrc-0.3.4-cp311-cp311-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 396.2 kB
  • Tags: CPython 3.11, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a84cae6c3d23f5dd0810027507daa74bbabe54e1d65628fcb7a41e1319f98d19
MD5 b49f6c4ffb556dd5b42597b60d35d989
BLAKE2b-256 9c707f6a2ec6bb358ca8f96194258fdec956c41c534e4ee70c6ac46e71a8cc8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: mtrc-0.3.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 653.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3a1a883b50ae512d50cf17f2115620564e392cd10e7ef31f79f17f25dffa277f
MD5 f18f48cef56d452d02814c84cf4e6eb4
BLAKE2b-256 de41c9c1bd4f4859d296d60c69549b89ae591016c24b88fdac2365dcd010a708

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp310-cp310-win_amd64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mtrc-0.3.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d373f9da6b68dc1462e48290ce6ae4bb70c6ec4e4a43911e939c24a0210dfa3a
MD5 1161107441263504495f0f2f1760ca1e
BLAKE2b-256 fa969ec77a4f40938fd88f683307d7e9c5e95bb94ceba407dbdb2bbc3ff25c78

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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

File details

Details for the file mtrc-0.3.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

  • Download URL: mtrc-0.3.4-cp310-cp310-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 391.8 kB
  • Tags: CPython 3.10, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mtrc-0.3.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5cc0a7c00e9490ecc607eaaa9ea3dea30fc01db3a7852edf69a1793333936b0a
MD5 833efe73bd19a46c95d4bff3c95913fb
BLAKE2b-256 8910e97dec1d8922c1374b7dd88bbc77f1148387e0dd32230a03ebf31e4c75af

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtrc-0.3.4-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on metric-space-ai/metric

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