Bindings for jsonpath-rust library

Overview

jsonpath-rust-bindings

PyPI - Downloads GitHub Workflow Status (with event) GitHub Workflow Status (with event) piwheels (including prereleases)

This package contains Python bindings for jsonpath-rust library by besok.

The details regarding the JsonPath itself can be found here.

Installation

pip install jsonpath-rust-bindings

Usage

from jsonpath_rust_bindings import Finder

sample = {
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95,
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99,
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99,
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99,
            },
        ],
        "bicycle": {"color": "red", "price": 19.95},
    },
    "expensive": 10,
}

queries = [
    '$.store.book[*].author',
    '$..book[?(@.isbn)]',
    '$.store.*',
    '$..author',
    '$.store..price',
    '$..book[2]',
    # '$..book[-2]',
    '$..book[0,1]',
    '$..book[:2]',
    '$..book[1:2]',
    '$..book[-2:]',
    '$..book[2:]',
    '$.store.book[?(@.price<10)]',
    '$..book[?(@.price<=$.expensive)]',
    "$..book[?(@.author ~= '.*Rees')].price",
    '$..*',
]

f = Finder(sample)

for query in queries:
    print(query, f.find(query), '\n')

# You will see a bunch of found items like
# $..book[?(@.author ~= '.*Rees')].price [JsonPathResult(data=8.95, path=Some("$.['store'].['book'][0].['price']"), is_new_value=False)]

JsonPathResult has the following attributes:

  • data: the found value
  • path: the path to the found value
  • is_new_value: whether the value is a new value or a copy of the original value

JsonPathResult can't be constructed from Python; it is only returned by Finder.find().

Caveats

The current implementation is cloning the original PyObject data when converting it to the serde Value. It happens each time you're creating a new Finder instance. Try to reuse the same Finder instance for querying if it's possible.

Also, It has yet another consequence demonstrated in the following example:

>>> original_object_i_want_to_mutate = {'a': {'b': 'sample b'}}
>>> from jsonpath_rust_bindings import Finder
>>> f = Finder(original_object_i_want_to_mutate)
>>> b_dict = f.find('$.a')[0].data
>>> b_dict
{'b': 'sample b'}
>>> b_dict['new'] = 42
>>> original_object_i_want_to_mutate
{'a': {'b': 'sample b'}}
You might also like...
Pollard's p - 1, in rust, with python bindings

Pollard's p - 1 algorithm for factorization Written in rust, using pyo3 to provide python bindings and primesieve for fast prime enumeration. libprime

hackernews_tui is a Terminal UI to browse Hacker News with vim-like key bindings.
hackernews_tui is a Terminal UI to browse Hacker News with vim-like key bindings.

hackernews_tui is written in Rust with the help of Cursive TUI library. It uses HN Algolia search APIs to get Hacker News data.

Songbird bindings for python

Songbird-Py Songbird bindings for python. The goal is to provide an easy to use alternitive to Lavalink. Its written with rust-bindings to Songbird. S

Unopinionated low level API bindings focused on soundness, safety, and stronger types over raw FFI.

πŸ”₯ firehazard πŸ”₯ Create a fire hazard by locking down your (Microsoft) Windows so nobody can escape (your security sandbox.) Unopinionated low level A

Python bindings for decancer.

decancer_py Python bindings for decancer. Installation You can get started with decancer_py by installing from PyPI: pip install -U decancer-py Usage

Kotlin bindings for yrs.

ykt Kotlin bindings for yrs. Getting started import uniffi.ykt.Doc fun main() { val doc = Doc() val text = doc.getText("my_text") val tx = doc

PyO3 bindings and Python interface to skani, a method for fast fast genomic identity calculation using sparse chaining.

🐍 ⛓️ 🧬 Pyskani PyO3 bindings and Python interface to skani, a method for fast fast genomic identity calculation using sparse chaining. πŸ—ΊοΈ Overview

pyrevm Blazing-fast Python bindings to revm

pyrevm Blazing-fast Python bindings to revm Quickstart make install make test Example Usage Here we show how you can fork from Ethereum mainnet and s

RocksDB-based queue with python bindings

RocksQ An inproc RocksDB-based queue with Python bindings. It is implemented in Rust. Features: max capacity limit in number of elements; size calcula

Owner
Igor
Igor
Rust bindings to the Vectorscan high-performance regex library

vectorscan-rs Overview This repository contains Rust bindings to the high-performance Vectorscan regular expression library. The bindings are organize

Brad Larsen 5 Apr 9, 2024
A library to generate bindings from Cairo ABI.

Cainome: bindings generation from Cairo ABI Cainome is a library to generate bindings from Cairo ABI. Cainome architecture provides a flexible way to

null 6 Dec 22, 2023
Wrapper around atspi-code to provide higher-level at-spi Rust bindings

atspi Wrapper around atspi-codegen to provide higher-level at-spi Rust bindings. Contributions Take a look at our atspi-codegen crate, and try inpleme

Odilia 3 Feb 7, 2022
Rust bindings to libcurl

curl-rust libcurl bindings for Rust Quick Start use std::io::{stdout, Write}; use curl::easy::Easy; // Print a web page onto stdout fn main() {

Alex Crichton 885 Jan 9, 2023
Rust bindings for the JavaScriptCore engine.

JavaScriptCore API for Rust This library provides a Rust API for the JavaScriptCore engine with the following goals: High-level API like the JavaScrip

Pekka Enberg 48 Dec 27, 2022
Rust bindings to the RVVM's public api

rvvm [WIP] Safe Rust bindings to the RVVM's public API. Provides the Rust-idiomatic interface to the RVVM public API. Implemented Virtual machine crea

null 3 Jan 9, 2023
⚑️ Python bindings for a rust implementation of aapleby's MurMurHash.

?? murmurh ?? ⚑️ Python bindings for a rust implementation of aapleby's MurMurHash. ?? Contributing Contributions are welcome! Please feel free to ope

Paul Leydier 6 Jan 14, 2023
"Rust bindings for the Matlab C API"

matlab-sys matlab-sys provides low level bindings to Matlab's C API. This allows writing MEX functions, using the C Matrix API, interacting with the C

null 11 Feb 28, 2023
nvim-oxi provides safe and idiomatic Rust bindings to the rich API exposed by the Neovim text editor.

?? nvim-oxi nvim-oxi provides safe and idiomatic Rust bindings to the rich API exposed by the Neovim text editor. The project is mostly intended for p

Riccardo Mazzarini 655 Jul 13, 2023
API bindings, CLI client and FUSE filesystem for Wiki.js written in Rust.

wikijs-rs API bindings, CLI client and FUSE filesystem for Wiki.js written in Rust. What's inside? Library: Rust bindings to Wiki.js's entire GraphQL

Sandro-Alessio Gierens 4 Sep 19, 2023