drf-smart-nested-parser 0.1.0__py3-none-any.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,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: drf_smart_nested_parser
3
+ Version: 0.1.0
4
+ Summary: Smart nested parser for DRF (JSON + multipart + files)
5
+ Home-page: https://github.com/AmirHosseinDonyaei/drf_smart_nested_parser
6
+ Author: AmirHosseinDonyaei
7
+ License: MIT
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Framework :: Django
10
+ Classifier: Framework :: Django :: 4
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: djangorestframework>=3.14
16
+ Dynamic: author
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
25
+
26
+ # DRF Smart Nested Parser
27
+
28
+ A simple parser for Django REST Framework that converts `form-data` and `application/x-www-form-urlencoded` inputs into nested structures (dict / list). For JSON, it uses the default DRF JSON parser without additional conversion.
29
+
30
+ ## Installation
31
+
32
+ If you're using this package locally, ensure it is importable from your project. If published on PyPI, install it by the package name.
33
+
34
+ ## Usage
35
+
36
+ ### Add to DRF settings
37
+
38
+ ```python
39
+ # settings.py
40
+ REST_FRAMEWORK = {
41
+ "DEFAULT_PARSER_CLASSES": [
42
+ "drf_smart_nested_parser.SmartNestedParser",
43
+ ]
44
+ }
45
+ ```
46
+
47
+ ### Or only for a single view
48
+
49
+ ```python
50
+ from rest_framework.views import APIView
51
+ from drf_smart_nested_parser import SmartNestedParser
52
+
53
+ class MyView(APIView):
54
+ parser_classes = [SmartNestedParser]
55
+ ```
56
+
57
+ ## Input and Output
58
+
59
+ ### Example for `multipart/form-data` or `application/x-www-form-urlencoded`
60
+
61
+ Form keys with bracket notation (`[]`) are converted to nested structures:
62
+
63
+ ```
64
+ user[name] = Amir
65
+ user[age] = 30
66
+ items[0][title] = Book
67
+ items[0][price] = 120
68
+ items[1][title] = Pen
69
+ ```
70
+
71
+ Output:
72
+
73
+ ```json
74
+ {
75
+ "user": {
76
+ "name": "Amir",
77
+ "age": 30
78
+ },
79
+ "items": [
80
+ {"title": "Book", "price": 120},
81
+ {"title": "Pen"}
82
+ ]
83
+ }
84
+ ```
85
+
86
+ Note: If a value can be converted to a number, it will be cast to `int`.
87
+
88
+ ## Parser Behavior
89
+
90
+ - If `Content-Type` includes `application/json`, DRF's `JSONParser` is used.
91
+ - If `Content-Type` includes `multipart/form-data`, data is parsed and keys are converted to nested structures.
92
+ - Otherwise (e.g. `application/x-www-form-urlencoded`), `FormParser` is used and the same conversion applies.
93
+
94
+ ## Limitations and Notes
95
+
96
+ - Keys should start with a string root (e.g. `items[0]` should be used as part of a root like `items[0][name]` or at least `items[0]` alongside a textual root). A valid example: `items[0][name]`.
97
+ - File values in `multipart/form-data` are kept in `files` and are not modified.
98
+
99
+ ## Development
100
+
101
+ Code layout:
102
+
103
+ - `parsers.py`: `SmartNestedParser` implementation
104
+ - `utils.py`: `parse_nested_keys` helper
105
+
106
+ ## License
107
+
108
+ MIT
@@ -0,0 +1,4 @@
1
+ drf_smart_nested_parser-0.1.0.dist-info/METADATA,sha256=H9sHHkaqBsRUdmor4Egm-phN2i7BQIr82GBC3VxCgnk,2822
2
+ drf_smart_nested_parser-0.1.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
3
+ drf_smart_nested_parser-0.1.0.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
4
+ drf_smart_nested_parser-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+