csonpath 0.12.0__cp38-cp38-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,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,182 @@
1
+ Metadata-Version: 2.1
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
+
9
+ # csonpath
10
+
11
+ > that's not my path, that's not your path, but csonpath
12
+
13
+ [![Project Sandbox](https://docs.outscale.com/fr/userguide/_images/Project-Sandbox-yellow.svg)](https://docs.outscale.com/en/userguide/Open-Source-Projects.html)
14
+
15
+ **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.
16
+
17
+ ## 🌐 Links
18
+
19
+ - Project website: https://github.com/outscale/csonpath
20
+ - Join our community on [Discord](https://discord.gg/HUVtY5gT6s)
21
+
22
+
23
+ ## πŸ“„ Table of Contents
24
+
25
+ - [Overview](#-overview)
26
+ - [Requirements](#-requirements)
27
+ - [Installation](#-installation)
28
+ - [Configuration](#-configuration)
29
+ - [Usage](#-usage)
30
+ - [Examples](#-examples)
31
+ - [License](#-license)
32
+ - [Contributing](#-contributing)
33
+
34
+
35
+ ## πŸš€ Features
36
+
37
+ ### jsonpath
38
+ - support simple path like ex: `"$.a[3]["oui"]`
39
+ - support `..`: `"$..non`
40
+ - support `[*]`: `"$.array[*].obj[*].field"`
41
+ - support filters:
42
+ - with `>` or `<`: `"$.obj[?field > 123]"`
43
+ - with `=` or '!=': `"$.obj[?field != "123"]"`
44
+ - with regex, using POSIX regcom: `"$.obj[?.field ~= "123"]"`
45
+ - with `&`: `"$.obj[?field != "123" & second = 1]"`
46
+ - support `|`: `"$.obj | $.otherobj"`
47
+ - support subpath: `$.obj[$.key]`, even in filter `$.obj[?field > $.value]`
48
+ ### Functions
49
+ - **Find First**: Retrieve the first value matching a path.
50
+ - **Find All**: Retrieve all values matching a path.
51
+ - **Update or Create**: Update values or create new ones according to the path.
52
+ - **Remove**: Remove values matching a path.
53
+ - **Update or Create Callback**: Update values or create new ones according to the path, using a user-define callback.
54
+ - **Callback**: Call a callback according to the path.
55
+ - **Supports both C (using json-c) and Python objects.**
56
+
57
+ ## βœ… Getting Started
58
+
59
+ ### Prerequisites
60
+
61
+ - C compiler (gcc/clang)
62
+ - [json-c](https://github.com/json-c/json-c) library for C usage
63
+ - Python 3.x (for Python bindings)
64
+
65
+ ### Build
66
+
67
+ To build the C tests and examples:
68
+
69
+ ```sh
70
+ make
71
+ ```
72
+
73
+ ### Usage (json-c)
74
+
75
+ See examples in [`tests/json-c/get-a.c`](tests/json-c/get-a.c):
76
+
77
+ ```c
78
+ #include "csonpath_json-c.h"
79
+
80
+ const char *json_str = "{ \"a\": \"value\", \"array\": [1,2,3] }";
81
+ struct csonpath p;
82
+ struct json_object *jobj = json_tokener_parse(json_str);
83
+ struct json_object *ret;
84
+
85
+ csonpath_init(&p, "$.a");
86
+ ret = csonpath_find_first(&p, jobj);
87
+ // ret now points to "value"
88
+ ```
89
+
90
+ #### Avaible functions:
91
+ ```C
92
+ int csonpath_init(struct csonpath cjp[static 1], const char path[static 1])
93
+ ```
94
+ init a csonpath struct
95
+
96
+ ```C
97
+ int csonpath_set_path(struct csonpath cjp[static 1], const char path[static 1])
98
+ ```
99
+ change the path of a struct
100
+
101
+ ```C
102
+ int csonpath_compile(struct csonpath cjp[static 1])
103
+ ```
104
+ compile the path, doesn't need to be called before using it, but can be useful to catch error earlyer.
105
+ ```C
106
+ void csonpath_print_instruction(struct csonpath cjp[static 1])
107
+ ```
108
+ print all instructions once compiled
109
+ ```C
110
+ struct json_object *csonpath_find_first(struct csonpath cjp[static 1], struct json_object *json);
111
+ ```
112
+ Retrieve the first value matching a path
113
+ ```C
114
+ struct json_object *csonpath_find_all(struct csonpath cjp[static 1], struct json_object *json);
115
+ ```
116
+ Retrieve all values matching a path, return need to be free using `json_object_put`
117
+ ```C
118
+ struct json_object *csonpath_remove(struct csonpath cjp[static 1], struct json_object *json);
119
+ ```
120
+ Remove all matching elements from json
121
+ ```C
122
+ struct json_object *csonpath_update_or_create(struct csonpath cjp[static 1], struct json_object *json, struct json_object *new_val)
123
+ ```
124
+ update and push new_val, in json.
125
+ ```C
126
+ struct json_object *csonpath_callback(struct csonpath cjp[static 1], struct json_object *json, json_c_callback callback, void *userdata)
127
+ ```
128
+ call `callback` on each value matching path
129
+ ```C
130
+ struct json_object *csonpath_update_or_create_callback(struct csonpath cjp[static 1], struct json_object *json, json_c_callback callback, void *userdata)
131
+ ```
132
+ like callback, but update json base on the path, along the way.
133
+
134
+ ### Usage (Python)
135
+
136
+ #### Example
137
+ ```python
138
+ import csonpath
139
+
140
+ d = { "a": "value", "array": [1,2,3] }
141
+ o = csonpath.CsonPath("$.a")
142
+ print(o.find_first(d)) # Output: "value"
143
+ ```
144
+
145
+ #### Avaible methodes:
146
+ - `CsonPath(path)`: create a new csonpath object.
147
+ - `CsonPath(path, return_empty_array)`: Create a new csonpath object and return an empty list instead of None (like jsonpath-ng).
148
+ - `OBJ.find_first(self, json)`: take a json, return first found occurrence.
149
+ - `OBJ.find_all(self, json)`: take a json, return all found occurrence in a list.
150
+ - `OBJ.remove(self, json)`: take a json, remove all found occurrence from it.
151
+ - `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.
152
+ - `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.
153
+ - `OBJ.callback(self, json, callback, callback_data)`: take a json, call a callback, an all occurrence.
154
+
155
+ `callback` is a function that take 4 arguments: `parent`, `idx`, `cur_value` and `callback_data`
156
+
157
+ Check [`tests`](tests/python/) for more examples
158
+
159
+ ### Backends and Direct Usage
160
+
161
+ 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.
162
+
163
+ 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.
164
+
165
+ ## Directory Structure
166
+
167
+ - `csonpath.h`, `csonpath_do.h` - Main implementation files
168
+ - `csonpath_json-c.h` - Json-C implementation, use it by including "csonpath_json-c.h" directly in your source
169
+ - `csonpath_python.c` - python implementation, use it like a python lib (so `pip install .`)
170
+ - `tests/` - Contains tests
171
+ - `bench/` - Some benchmarks
172
+
173
+ ## 🀝 Contributing
174
+
175
+ We welcome contributions!
176
+
177
+ Please read our [Contributing Guidelines](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) before submitting a pull request.
178
+
179
+ Feel free to open issues or pull requests!
180
+
181
+ ## πŸ“œ License
182
+ BSD 3-Clause. See [LICENSE](LICENSE).
@@ -0,0 +1,6 @@
1
+ csonpath.cp38-win_amd64.pyd,sha256=UoWtsyu1OZezm7sRsMc16YD6WdDFPlPEKIALGETZvFg,69632
2
+ csonpath-0.12.0.dist-info/LICENSE,sha256=r62AJfGxdC1dXmsT7dgo7ocF0XZJaNpXFHq2FvMi5T0,1523
3
+ csonpath-0.12.0.dist-info/METADATA,sha256=dkCocCeZfFTdAfhzo2l4Qwtksc4SckR3p3zyyYBST08,6965
4
+ csonpath-0.12.0.dist-info/WHEEL,sha256=TFndZn0SXD1XqMUEIKDojL47weLF1ldHBOPnF9B_sLo,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 (75.3.4)
3
+ Root-Is-Purelib: false
4
+ Tag: cp38-cp38-win_amd64
5
+
@@ -0,0 +1 @@
1
+ csonpath
Binary file