Skip to main content

synaops

Rust implementations of the JSON and JSON-schema operations used by synalinks, exposed to Python as a PyO3 extension module (synaops).

The goal is a drop-in, faster replacement for the equivalent pure-Python helpers. Input/output types are plain Python dict / list / scalars — the boundary is handled via pythonize, so callers do not need to know there is Rust underneath.

Parity with the Python reference is asserted on every op and payload size (see bench/test_parity.py). Headline speedups on realistic payloads: ~485× on factorize_schema, ~280× on factorize_json at 600 keys, 4–8× on masking ops, 2–4× on simple key rewrites. Full table below.

Build

pip install maturin
maturin develop --release   # builds and installs into the active venv

Python API

import synaops

JSON object operations

Function Signature Description
prefix_json (json, prefix) Prepend prefix_ to every top-level key.
suffix_json (json, suffix) Append _suffix to every top-level key.
concatenate_json (json1, json2) Merge two objects; on key collision append _1, _2, … to disambiguate.
factorize_json (json) Group keys sharing a singular base into a single array under the plural key.
out_mask_json (json, mask=None, pattern=None, recursive=True) Drop keys whose base name is in mask or whose base name matches the regex pattern. Numerical suffixes are ignored when matching.
in_mask_json (json, mask=None, pattern=None, recursive=True) Keep only the keys whose base name is in mask or matches pattern. In recursive mode, arrays are preserved and their object items are filtered in place.

JSON schema operations

Operate on JSON-Schema-shaped dicts (properties, required, $defs, type, …).

Function Signature Description
prefix_schema (schema, prefix) Prepend prefix_ to every property key and update title / required accordingly.
suffix_schema (schema, suffix) Append _suffix to every property key and update title / required accordingly.
concatenate_schema (schema1, schema2) Merge two schemas (properties, required, $defs); on key collision append numeric suffixes and regenerate titles.
factorize_schema (schema) Group similar singular-keyed properties into array-typed plural-keyed properties; folds heterogeneous items into anyOf.
out_mask_schema (schema, mask=None, pattern=None, recursive=True) Remove properties whose base name is in mask or matches pattern. With recursive=True, descends into nested object/array properties and $defs, then prunes $defs entries no longer referenced.
in_mask_schema (schema, mask=None, pattern=None, recursive=True) Keep only properties whose base name is in mask or matches pattern. Same recursive/$defs-pruning behavior as out_mask_schema.
standardize_schema (schema) Placeholder for schema normalization (currently identity).

is_object, is_array, is_schema_equal, contains_schema are intentionally not ported. They are single-key lookups or dict comparisons whose cost is dominated by the PyO3 / dict-conversion boundary, so the pure-Python versions in synalinks are faster.

Matching semantics

Both *_mask_* families and factorize_* rely on the NLP helpers in nlp_utils.rs: they strip trailing numerical suffixes (answer_3 → answer) and normalize singular/plural forms (answers ↔ answer) before comparing keys. The pattern argument is a regular expression matched via substring search against the base key (same semantics as Python's re.search).

Benchmark

Measured on realistic payloads: nested objects, arrays of $ref-based objects, schema $defs. Three payload sizes (12, 96, 600 top-level keys). Parity with the Python reference is verified before each timing run (pytest bench/test_parity.py, 45/45 pass).

Speedup summary

Ratio py_median / rs_median per op. Higher is better; dashed line is parity (1×).

speedup

Operation small (12) medium (96) large (600)
factorize_schema 8.78× 64.8× 485×
factorize_json 9.73× 46.2× 282×
in_mask_json 7.75× 7.11× 7.47×
out_mask_json 4.23× 4.12× 4.29×
out_mask_json_pattern 3.77× 4.15× 4.20×
in_mask_schema 4.83× 4.12× 4.15×
out_mask_schema 4.25× 3.78× 4.11×
prefix_schema 3.63× 3.62× 3.89×
suffix_schema 3.66× 3.64× 3.85×
concatenate_schema 2.21× 2.15× 2.85×
suffix_json 2.36× 2.22× 2.28×
concatenate_json 2.25× 2.18× 2.27×
prefix_json 2.26× 2.25× 2.26×

factorize_* scales super-linearly because the Python reference does repeated O(n) key scans per group; the Rust path groups in a single pass. Simple key rewrites (prefix_*, suffix_*, concatenate_*) are bounded by the PyO3 dict-conversion boundary, which is why they cluster around 2–4×.

Before (Python) vs After (Rust) — absolute medians

Log scale, lower is better. Rows are the three payload sizes.

before/after

See bench/README.md for the harness, payload shapes, and how to regenerate these charts.

Development

cargo test              # run Rust unit tests
maturin develop         # install debug build into venv
maturin develop --release

# Parity + performance against the Python reference impl
pytest bench/test_parity.py -v
pytest bench/test_bench.py --benchmark-save=latest
python bench/plot.py    # writes bench/speedup.png

License

Apache-2.0

Metadata

Release files for synaops 0.2.2

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

Source distribution (sdist)

Source distribution for synaops 0.2.2
File Size Uploaded Provenance Actions
synaops-0.2.2.tar.gz 406.9 kB Without provenance Details for synaops-0.2.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for synaops 0.2.2
File Actions
synaops-0.2.2-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for synaops-0.2.2-cp310-abi3-win_amd64.whl
synaops-0.2.2-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for synaops-0.2.2-cp310-abi3-musllinux_1_2_x86_64.whl
synaops-0.2.2-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for synaops-0.2.2-cp310-abi3-musllinux_1_2_aarch64.whl
synaops-0.2.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for synaops-0.2.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
synaops-0.2.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for synaops-0.2.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
synaops-0.2.2-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for synaops-0.2.2-cp310-abi3-macosx_11_0_arm64.whl
synaops-0.2.2-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for synaops-0.2.2-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 7.6 MB

Release files / synaops-0.2.2.tar.gz

Download URL synaops-0.2.2.tar.gz
Size 406.9 kB
Tags Source
SHA-256 checksum
How to use checksums
752a9caa08387ba9f5df1f71fe81b8a41ea464233f5bbea6c84358f9b0e260c5
BLAKE2b-256 checksum
How to use checksums
f3eea228d1d8dcb92d9276c6e0aad4eceab2944751cb5adab87a3dede131149f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / synaops-0.2.2-cp310-abi3-win_amd64.whl

Download URL synaops-0.2.2-cp310-abi3-win_amd64.whl
Size 810.8 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
045a132b111bcb0a0ac50165fb5d94d26b0543c4e2d552acd49a7c8a87a36f34
BLAKE2b-256 checksum
How to use checksums
cfe669121866526ed36d6b6cd74a4bd32d75348ad16feed79a60ce847f4bed7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / synaops-0.2.2-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL synaops-0.2.2-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.3 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
210aca5de527536f918973653ed76cdfa39a0e2b9cfe5f49c69910156df4a113
BLAKE2b-256 checksum
How to use checksums
69c774af701b61152bd0c907cd7322d1cc0f9ba2adc1e05e7cd390574cb4a684
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / synaops-0.2.2-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL synaops-0.2.2-cp310-abi3-musllinux_1_2_aarch64.whl
Size 1.2 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
bbfede5ea336de03d4f4cca1ffa098d8a438f5f30beeb4b261d6036b36674272
BLAKE2b-256 checksum
How to use checksums
06a6f2b14a440227cd7340ef90355774277864adf4fc1219f0cb12ec860d2b0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / synaops-0.2.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL synaops-0.2.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.0 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a566b1e5aa7f96671a8f20b5372e2de7d21d58f7f7873c515873c7271097e0a4
BLAKE2b-256 checksum
How to use checksums
473d90c066d16c40492b37779caafaa2ac3693530fd4ef85434b7a49b53cd6e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / synaops-0.2.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL synaops-0.2.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.0 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
f0ea24daa4c66d57668d09dc1de49ea06602518e39e56c20af65840ec8dae3a2
BLAKE2b-256 checksum
How to use checksums
41260c5ec27db0e180d5ec0c46574c65deea590a938dab99245f1eccf0f514b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / synaops-0.2.2-cp310-abi3-macosx_11_0_arm64.whl

Download URL synaops-0.2.2-cp310-abi3-macosx_11_0_arm64.whl
Size 897.3 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
89279fe1d92dcd10bba10291fb1edae57a4c8c6975ff55c93875e25c984b0156
BLAKE2b-256 checksum
How to use checksums
6f202daa55a446411b60c813c72954a0eb0516239ab75a0ad53bf55d9533869e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / synaops-0.2.2-cp310-abi3-macosx_10_12_x86_64.whl

Download URL synaops-0.2.2-cp310-abi3-macosx_10_12_x86_64.whl
Size 940.8 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
225b0d03e4fd468dc33a667e9415fda55c4283d13d95b3c211a66c1af4eed8a3
BLAKE2b-256 checksum
How to use checksums
f092657c7dca937d63455443c24024da857dad6540dba06d7ec73784b1b57c70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Security for synaops 0.2.2

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