drf-smart-nested-parser 0.1.0__tar.gz

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,83 @@
1
+ # DRF Smart Nested Parser
2
+
3
+ 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.
4
+
5
+ ## Installation
6
+
7
+ If you're using this package locally, ensure it is importable from your project. If published on PyPI, install it by the package name.
8
+
9
+ ## Usage
10
+
11
+ ### Add to DRF settings
12
+
13
+ ```python
14
+ # settings.py
15
+ REST_FRAMEWORK = {
16
+ "DEFAULT_PARSER_CLASSES": [
17
+ "drf_smart_nested_parser.SmartNestedParser",
18
+ ]
19
+ }
20
+ ```
21
+
22
+ ### Or only for a single view
23
+
24
+ ```python
25
+ from rest_framework.views import APIView
26
+ from drf_smart_nested_parser import SmartNestedParser
27
+
28
+ class MyView(APIView):
29
+ parser_classes = [SmartNestedParser]
30
+ ```
31
+
32
+ ## Input and Output
33
+
34
+ ### Example for `multipart/form-data` or `application/x-www-form-urlencoded`
35
+
36
+ Form keys with bracket notation (`[]`) are converted to nested structures:
37
+
38
+ ```
39
+ user[name] = Amir
40
+ user[age] = 30
41
+ items[0][title] = Book
42
+ items[0][price] = 120
43
+ items[1][title] = Pen
44
+ ```
45
+
46
+ Output:
47
+
48
+ ```json
49
+ {
50
+ "user": {
51
+ "name": "Amir",
52
+ "age": 30
53
+ },
54
+ "items": [
55
+ {"title": "Book", "price": 120},
56
+ {"title": "Pen"}
57
+ ]
58
+ }
59
+ ```
60
+
61
+ Note: If a value can be converted to a number, it will be cast to `int`.
62
+
63
+ ## Parser Behavior
64
+
65
+ - If `Content-Type` includes `application/json`, DRF's `JSONParser` is used.
66
+ - If `Content-Type` includes `multipart/form-data`, data is parsed and keys are converted to nested structures.
67
+ - Otherwise (e.g. `application/x-www-form-urlencoded`), `FormParser` is used and the same conversion applies.
68
+
69
+ ## Limitations and Notes
70
+
71
+ - 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]`.
72
+ - File values in `multipart/form-data` are kept in `files` and are not modified.
73
+
74
+ ## Development
75
+
76
+ Code layout:
77
+
78
+ - `parsers.py`: `SmartNestedParser` implementation
79
+ - `utils.py`: `parse_nested_keys` helper
80
+
81
+ ## License
82
+
83
+ MIT
@@ -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,7 @@
1
+ README.md
2
+ setup.py
3
+ drf_smart_nested_parser.egg-info/PKG-INFO
4
+ drf_smart_nested_parser.egg-info/SOURCES.txt
5
+ drf_smart_nested_parser.egg-info/dependency_links.txt
6
+ drf_smart_nested_parser.egg-info/requires.txt
7
+ drf_smart_nested_parser.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ djangorestframework>=3.14
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,25 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="drf_smart_nested_parser",
5
+ version="0.1.0",
6
+ packages=find_packages(),
7
+ install_requires=[
8
+ "djangorestframework>=3.14",
9
+ ],
10
+ include_package_data=True,
11
+ description="Smart nested parser for DRF (JSON + multipart + files)",
12
+ long_description=open("README.md").read(),
13
+ long_description_content_type="text/markdown",
14
+ url="https://github.com/AmirHosseinDonyaei/drf_smart_nested_parser",
15
+ author="AmirHosseinDonyaei",
16
+ license="MIT",
17
+ classifiers=[
18
+ "Programming Language :: Python :: 3",
19
+ "Framework :: Django",
20
+ "Framework :: Django :: 4",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Operating System :: OS Independent",
23
+ ],
24
+ python_requires='>=3.7',
25
+ )