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_3answer) and normalize singular/plural forms (answersanswer) 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

Release files for synaops 0.2.1

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.1
File Size Uploaded
synaops-0.2.1.tar.gz 406.3 kB Details

Built distributions (wheels)

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

Total release size: 7.7 MB

Release files / synaops-0.2.1.tar.gz

Download URL synaops-0.2.1.tar.gz
Size 406.3 kB
Tags Source
SHA-256 checksum
How to use checksums
637afd39e6f36a1caaebfc1aca035b705256c88020d20f7902ff97e8ab50dc1c
BLAKE2b-256 checksum
How to use checksums
8a9c50162352aeeeff5dbeac006e117947fd37a234c0129fbf63a4a878f1e251
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

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

Download URL synaops-0.2.1-cp310-abi3-win_amd64.whl
Size 830.1 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1856daae7a3769a7d15755d9e9fc322049cd8d534bf55ee59e3cbd36a400c718
BLAKE2b-256 checksum
How to use checksums
05b38004a06a2e539546541858f0d56536fc56b859b124aaf0cb2b4c8d17266d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

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

Download URL synaops-0.2.1-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
85652f6d1fbd40d5d476c3e10db66585cc2095a37a2857a01b03c6a62cbf5021
BLAKE2b-256 checksum
How to use checksums
0cf4d8c9018064ae32a6c3c2fb70aac733b85203547023d0cde0038c36fecceb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

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

Download URL synaops-0.2.1-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
25d5d2c9804cfc007824ee92d26d791ef67b4a3ea194c1378055a05fb223981b
BLAKE2b-256 checksum
How to use checksums
ac341045297d5473d9f1c2dac11972ca5207e3b0992a0b19ae96ade81cb35116
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

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

Download URL synaops-0.2.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
09245eec17230b3168aee82e096ecfb3a1351ad1cb5c1de265aca67db7ae6948
BLAKE2b-256 checksum
How to use checksums
609777e4e5c64bdf8058375e623159b840b20dd114ac9df4ad6b6192a7ea4ff8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

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

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

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

Download URL synaops-0.2.1-cp310-abi3-macosx_11_0_arm64.whl
Size 924.4 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
96264ce575c287911d65c524bf73eb5318dfb3093756ac9940d69147d798d637
BLAKE2b-256 checksum
How to use checksums
f090128917a33538fe8bc2f04474daa5efda94dcdba7e81b5eab4d0cf4e53e1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

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

Download URL synaops-0.2.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 965.5 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0f5a63b215d365d1fb17c60b9f9c3de14709fdd4e19e93c951dbc4c2f1af45c3
BLAKE2b-256 checksum
How to use checksums
86292e96f87925ab14c6f86dfcddc38a3bfa4214180e78d2166577c430b39cfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release history Release notifications | RSS feed

This release

0.2.1 This release

8 release files

0.2.0

8 release files

0.1.0

8 release files

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