csonpath 0.12.0__cp39-cp39-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,183 @@
1
+ Metadata-Version: 2.4
2
+ Name: csonpath
3
+ Version: 0.12.0
4
+ Description-Content-Type: text/markdown
5
+ License-File: LICENSE
6
+ Provides-Extra: dev
7
+ Requires-Dist: pytest>=8.3.5; extra == "dev"
8
+ Dynamic: license-file
9
+
10
+ # csonpath
11
+
12
+ > that's not my path, that's not your path, but csonpath
13
+
14
+ [![Project Sandbox](https://docs.outscale.com/fr/userguide/_images/Project-Sandbox-yellow.svg)](https://docs.outscale.com/en/userguide/Open-Source-Projects.html)
15
+
16
+ **csonpath** is a partial [JSONPath](https://goessner.net/articles/JsonPath/) implementation in C, with Python bindings. It allows you to query, update, and remove data from JSON objects using path expressions.
17
+
18
+ ## 🌐 Links
19
+
20
+ - Project website: https://github.com/outscale/csonpath
21
+ - Join our community on [Discord](https://discord.gg/HUVtY5gT6s)
22
+
23
+
24
+ ## πŸ“„ Table of Contents
25
+
26
+ - [Overview](#-overview)
27
+ - [Requirements](#-requirements)
28
+ - [Installation](#-installation)
29
+ - [Configuration](#-configuration)
30
+ - [Usage](#-usage)
31
+ - [Examples](#-examples)
32
+ - [License](#-license)
33
+ - [Contributing](#-contributing)
34
+
35
+
36
+ ## πŸš€ Features
37
+
38
+ ### jsonpath
39
+ - support simple path like ex: `"$.a[3]["oui"]`
40
+ - support `..`: `"$..non`
41
+ - support `[*]`: `"$.array[*].obj[*].field"`
42
+ - support filters:
43
+ - with `>` or `<`: `"$.obj[?field > 123]"`
44
+ - with `=` or '!=': `"$.obj[?field != "123"]"`
45
+ - with regex, using POSIX regcom: `"$.obj[?.field ~= "123"]"`
46
+ - with `&`: `"$.obj[?field != "123" & second = 1]"`
47
+ - support `|`: `"$.obj | $.otherobj"`
48
+ - support subpath: `$.obj[$.key]`, even in filter `$.obj[?field > $.value]`
49
+ ### Functions
50
+ - **Find First**: Retrieve the first value matching a path.
51
+ - **Find All**: Retrieve all values matching a path.
52
+ - **Update or Create**: Update values or create new ones according to the path.
53
+ - **Remove**: Remove values matching a path.
54
+ - **Update or Create Callback**: Update values or create new ones according to the path, using a user-define callback.
55
+ - **Callback**: Call a callback according to the path.
56
+ - **Supports both C (using json-c) and Python objects.**
57
+
58
+ ## βœ… Getting Started
59
+
60
+ ### Prerequisites
61
+
62
+ - C compiler (gcc/clang)
63
+ - [json-c](https://github.com/json-c/json-c) library for C usage
64
+ - Python 3.x (for Python bindings)
65
+
66
+ ### Build
67
+
68
+ To build the C tests and examples:
69
+
70
+ ```sh
71
+ make
72
+ ```
73
+
74
+ ### Usage (json-c)
75
+
76
+ See examples in [`tests/json-c/get-a.c`](tests/json-c/get-a.c):
77
+
78
+ ```c
79
+ #include "csonpath_json-c.h"
80
+
81
+ const char *json_str = "{ \"a\": \"value\", \"array\": [1,2,3] }";
82
+ struct csonpath p;
83
+ struct json_object *jobj = json_tokener_parse(json_str);
84
+ struct json_object *ret;
85
+
86
+ csonpath_init(&p, "$.a");
87
+ ret = csonpath_find_first(&p, jobj);
88
+ // ret now points to "value"
89
+ ```
90
+
91
+ #### Avaible functions:
92
+ ```C
93
+ int csonpath_init(struct csonpath cjp[static 1], const char path[static 1])
94
+ ```
95
+ init a csonpath struct
96
+
97
+ ```C
98
+ int csonpath_set_path(struct csonpath cjp[static 1], const char path[static 1])
99
+ ```
100
+ change the path of a struct
101
+
102
+ ```C
103
+ int csonpath_compile(struct csonpath cjp[static 1])
104
+ ```
105
+ compile the path, doesn't need to be called before using it, but can be useful to catch error earlyer.
106
+ ```C
107
+ void csonpath_print_instruction(struct csonpath cjp[static 1])
108
+ ```
109
+ print all instructions once compiled
110
+ ```C
111
+ struct json_object *csonpath_find_first(struct csonpath cjp[static 1], struct json_object *json);
112
+ ```
113
+ Retrieve the first value matching a path
114
+ ```C
115
+ struct json_object *csonpath_find_all(struct csonpath cjp[static 1], struct json_object *json);
116
+ ```
117
+ Retrieve all values matching a path, return need to be free using `json_object_put`
118
+ ```C
119
+ struct json_object *csonpath_remove(struct csonpath cjp[static 1], struct json_object *json);
120
+ ```
121
+ Remove all matching elements from json
122
+ ```C
123
+ struct json_object *csonpath_update_or_create(struct csonpath cjp[static 1], struct json_object *json, struct json_object *new_val)
124
+ ```
125
+ update and push new_val, in json.
126
+ ```C
127
+ struct json_object *csonpath_callback(struct csonpath cjp[static 1], struct json_object *json, json_c_callback callback, void *userdata)
128
+ ```
129
+ call `callback` on each value matching path
130
+ ```C
131
+ struct json_object *csonpath_update_or_create_callback(struct csonpath cjp[static 1], struct json_object *json, json_c_callback callback, void *userdata)
132
+ ```
133
+ like callback, but update json base on the path, along the way.
134
+
135
+ ### Usage (Python)
136
+
137
+ #### Example
138
+ ```python
139
+ import csonpath
140
+
141
+ d = { "a": "value", "array": [1,2,3] }
142
+ o = csonpath.CsonPath("$.a")
143
+ print(o.find_first(d)) # Output: "value"
144
+ ```
145
+
146
+ #### Avaible methodes:
147
+ - `CsonPath(path)`: create a new csonpath object.
148
+ - `CsonPath(path, return_empty_array)`: Create a new csonpath object and return an empty list instead of None (like jsonpath-ng).
149
+ - `OBJ.find_first(self, json)`: take a json, return first found occurrence.
150
+ - `OBJ.find_all(self, json)`: take a json, return all found occurrence in a list.
151
+ - `OBJ.remove(self, json)`: take a json, remove all found occurrence from it.
152
+ - `OBJ.update_or_create(self, json, value)`: take a json, replace all found occurrence from it, by the value, if doesn't found something, create it.
153
+ - `OBJ.update_or_create_callback(self, json, callback, callback_data)`: take a json, if it doesn't find a parent object, create it, then it calls a callback.
154
+ - `OBJ.callback(self, json, callback, callback_data)`: take a json, call a callback, an all occurrence.
155
+
156
+ `callback` is a function that take 4 arguments: `parent`, `idx`, `cur_value` and `callback_data`
157
+
158
+ Check [`tests`](tests/python/) for more examples
159
+
160
+ ### Backends and Direct Usage
161
+
162
+ csonpath is inspired by JSONPath, but is designed to be backend-agnostic: it can work with any C library or environment that manipulates array, object, and scalar typesβ€”not just JSON. Out of the box, backends for Python and json-c are provided, but you can create your own backend for other formats such as YAML, or any custom data structure.
163
+
164
+ To use csonpath with a different data type or library, simply define the required macros and types in a header file (similar to `csonpath_json-c.h` or `csonpath_python.c`), then include your backend header before `csonpath.h`. This approach allows you to adapt csonpath for manipulating data in any format that supports array/object semantics, giving you full flexibility beyond just JSON.
165
+
166
+ ## Directory Structure
167
+
168
+ - `csonpath.h`, `csonpath_do.h` - Main implementation files
169
+ - `csonpath_json-c.h` - Json-C implementation, use it by including "csonpath_json-c.h" directly in your source
170
+ - `csonpath_python.c` - python implementation, use it like a python lib (so `pip install .`)
171
+ - `tests/` - Contains tests
172
+ - `bench/` - Some benchmarks
173
+
174
+ ## 🀝 Contributing
175
+
176
+ We welcome contributions!
177
+
178
+ Please read our [Contributing Guidelines](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) before submitting a pull request.
179
+
180
+ Feel free to open issues or pull requests!
181
+
182
+ ## πŸ“œ License
183
+ BSD 3-Clause. See [LICENSE](LICENSE).
@@ -0,0 +1,6 @@
1
+ csonpath.cp39-win_amd64.pyd,sha256=aSvSsruEcDcYg51R23VzCRORlzV3E7QbnxnEZi64ny0,69120
2
+ csonpath-0.12.0.dist-info/licenses/LICENSE,sha256=r62AJfGxdC1dXmsT7dgo7ocF0XZJaNpXFHq2FvMi5T0,1523
3
+ csonpath-0.12.0.dist-info/METADATA,sha256=u8ZkUsOfZmLkFKc_s8NdfcxE0cW-x76OobO_eDcGzKc,6988
4
+ csonpath-0.12.0.dist-info/WHEEL,sha256=zuNlb9Um05hyCt8XRmFaVi795Ee7Bc9lOiOIpwTM7Gs,99
5
+ csonpath-0.12.0.dist-info/top_level.txt,sha256=ZOMMEnRWLGdlvjqaFqS1nxU7iqQEPT9JoYjlvPLmdJo,9
6
+ csonpath-0.12.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp39-cp39-win_amd64
5
+
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, Outscale
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ csonpath
Binary file