django-api-versioning 0.1.0__tar.gz → 0.1.2__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. {django-api-versioning-0.1.0/django_api_versioning.egg-info → django-api-versioning-0.1.2}/PKG-INFO +20 -17
  2. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/README.md +17 -14
  3. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/django_api_versioning/decorators.py +10 -4
  4. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/django_api_versioning/settings.py +4 -6
  5. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2/django_api_versioning.egg-info}/PKG-INFO +20 -17
  6. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/setup.py +9 -3
  7. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/.pre-commit-config.yaml +0 -0
  8. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/LICENSE +0 -0
  9. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/MANIFEST.in +0 -0
  10. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/django_api_versioning/__init__.py +0 -0
  11. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/django_api_versioning/exceptions.py +0 -0
  12. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/django_api_versioning/registry.py +0 -0
  13. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/django_api_versioning/urls.py +0 -0
  14. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/django_api_versioning.egg-info/SOURCES.txt +0 -0
  15. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/django_api_versioning.egg-info/dependency_links.txt +0 -0
  16. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/django_api_versioning.egg-info/requires.txt +0 -0
  17. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/django_api_versioning.egg-info/top_level.txt +0 -0
  18. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/pyproject.toml +0 -0
  19. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/pytest.ini +0 -0
  20. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/requirements-dev.txt +0 -0
  21. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/requirements.txt +0 -0
  22. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/setup.cfg +0 -0
  23. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/tests/__init__.py +0 -0
  24. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/tests/test_decorators.py +0 -0
  25. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/tests/test_exceptions.py +0 -0
  26. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/tests/test_registry.py +0 -0
  27. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/tests/test_settings.py +0 -0
  28. {django-api-versioning-0.1.0 → django-api-versioning-0.1.2}/tests/test_urls.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django-api-versioning
3
- Version: 0.1.0
4
- Summary: A powerful and flexible library for managing API versioning in Django projects.
3
+ Version: 0.1.2
4
+ Summary: Django API versioning decorator provides a solution for managing multiple API versions within the Django framework, enabling versioning through URLs with backward compatibility and automatically registering routes.
5
5
  Home-page: https://github.com/mojtaba-arvin/django-api-versioning
6
6
  Author: Mojtaba Arvin
7
7
  Author-email: ArvinDevDay@gmail.com
@@ -15,12 +15,11 @@ Classifier: Development Status :: 3 - Alpha
15
15
  Classifier: Intended Audience :: Developers
16
16
  Classifier: License :: OSI Approved :: MIT License
17
17
  Classifier: Operating System :: OS Independent
18
- Requires-Python: >=3.9
18
+ Requires-Python: >=3.6
19
19
  Description-Content-Type: text/markdown
20
20
  Provides-Extra: dev
21
21
  License-File: LICENSE
22
22
 
23
-
24
23
  # Django API Versioning
25
24
 
26
25
  [![PyPI version](https://badge.fury.io/py/django-api-versioning.svg)](https://badge.fury.io/py/django-api-versioning)
@@ -28,7 +27,7 @@ License-File: LICENSE
28
27
  [![codecov](https://codecov.io/gh/mojtaba-arvin/django-api-versioning/branch/main/graph/badge.svg)](https://codecov.io/gh/mojtaba-arvin/django-api-versioning)
29
28
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
30
29
 
31
- **Django API Versioning** is a powerful and flexible library for managing API versioning in Django projects. It allows you to easily define and manage different versions of your API endpoints using decorators, ensuring backward compatibility and clean code organization.
30
+ **Django API Versioning** is a powerful and flexible library for managing [API versioning in Django](https://github.com/mojtaba-arvin/django-api-versioning) projects. It allows you to easily define and manage different versions of your API endpoints using decorators, ensuring backward compatibility and clean code organization.
32
31
 
33
32
  ## Features
34
33
 
@@ -41,7 +40,7 @@ License-File: LICENSE
41
40
 
42
41
  ## Installation
43
42
 
44
- You can install Django API Versioning via pip:
43
+ You can [install Django API Versioning](https://pypi.org/project/django-api-versioning/) via pip:
45
44
 
46
45
  ```bash
47
46
  pip install django-api-versioning
@@ -95,7 +94,6 @@ or you have already have a `ROOT_URLCONF` in settings, you only need to import t
95
94
 
96
95
  The `endpoint` decorator can be used in both function-based views (FBVs) and class-based views (CBVs). It's also fully compatible with `Django Rest Framework (DRF)`. The decorator allows you to define versioning for your API views and supports backward compatibility by default and you don't need to pass `backward=True` flag to the `endpoint` decorator.
97
96
 
98
-
99
97
  #### Example for Function-Based Views (FBVs):
100
98
 
101
99
  ```python
@@ -110,6 +108,7 @@ def users_view(request):
110
108
  In this example, the `users_view` function is decorated with the endpoint decorator. This specifies that the view is accessible under version `2` of the API and **supports backward compatibility**. The `backward=True` flag as default ensures that users can also access the previous version (version `1`) at `/api/v1/account_app/users`.
111
109
 
112
110
  #### Example for Class-Based Views (CBVs):
111
+
113
112
  For class-based views, you can apply the decorator to methods such as `get`, `post`, or any other HTTP method you need to handle. Here’s an example:
114
113
 
115
114
  ```python
@@ -130,7 +129,6 @@ class UsersView(View):
130
129
 
131
130
  If you have already installed [Django Rest Framework](https://www.django-rest-framework.org/#installation), the `endpoint` decorator can be easily applied to APIView or viewsets. Here’s an example with a DRF APIView:
132
131
 
133
-
134
132
  ```python
135
133
  from rest_framework.views import APIView
136
134
  from rest_framework.response import Response
@@ -144,25 +142,26 @@ class UsersAPIView(APIView):
144
142
  ```
145
143
 
146
144
  #### URL Generation Based on Versioning:
145
+
147
146
  Once the decorator is applied, the URLs for your API will be generated based on the version specified in the decorator. For example, if the `API_MIN_VERSION` in your settings.py is set to `1` and the version in the decorator is set to `2`, the following URLs will be available:
148
147
 
149
- * `/api/v1/account_app/users`
150
- * `/api/v2/account_app/users`
148
+ - `/api/v1/account_app/users`
149
+ - `/api/v2/account_app/users`
151
150
 
152
151
  The `API_MIN_VERSION` setting ensures that users can access the API using different versions, providing backward compatibility. You can adjust which versions are considered valid by modifying the `API_MIN_VERSION` and `version` numbers in the decorators.
153
152
 
154
153
  #### Additional Configuration Options:
155
154
 
156
155
  **Without `app_name`:** If you don't pass `app_name` in the decorator, like this:
156
+
157
157
  ```python
158
158
  @endpoint("users", version=2, view_name="users_list_api")
159
159
  ```
160
160
 
161
161
  The generated URLs will be:
162
162
 
163
- * `/api/v1/users`
164
- * `/api/v2/users`
165
-
163
+ - `/api/v1/users`
164
+ - `/api/v2/users`
166
165
 
167
166
  **Without `version`:** If you don't pass `version` in the decorator, like this:
168
167
 
@@ -172,7 +171,7 @@ The generated URLs will be:
172
171
 
173
172
  API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for that view. The only URL generated will be:
174
173
 
175
- * `/users`
174
+ - `/users`
176
175
 
177
176
  **Setting `backward=False`:** By default, the `backward` parameter is set to `True`, which ensures backward compatibility. If you explicitly set `backward=False`, like this:
178
177
 
@@ -182,7 +181,7 @@ API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for
182
181
 
183
182
  The generated URL will be only version 2:
184
183
 
185
- * `api/v2/users`
184
+ - `api/v2/users`
186
185
 
187
186
  4. Run the Server:
188
187
 
@@ -191,16 +190,21 @@ python manage.py runserver
191
190
  ```
192
191
 
193
192
  ## Notes
193
+
194
194
  ### 1. `API_BASE_PATH` in settings Must Include ‍‍`{version}`:
195
+
195
196
  The `API_BASE_PATH` should always include `{version}` to ensure proper API versioning. This is important for correctly mapping API routes to different versions.
196
197
 
197
198
  ### 2. Using `app_name` in the `endpoint` decorator:
199
+
198
200
  It's recommended to fill in the `app_name` in the `endpoint` decorator to make the API URLs **more unique and organized**. This ensures that the routes are scoped under the correct app, avoiding potential conflicts and making them easier to manage.
199
201
 
200
202
  ### 3. Views with Version Less Than `API_MIN_VERSION` Are Automatically Ignored:
203
+
201
204
  Any view whose `version` is less than the `API_MIN_VERSION` will be automatically ignored. This means clients will no longer have access to these older versions, **without the need to manually edit or remove code**. This is handled automatically by the package.
202
205
 
203
206
  ### 4. URLs for Versions Between `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION`:
207
+
204
208
  Endpoints that have versions within the range defined by `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION` will always have a corresponding URL generated. This ensures that only valid versions will be accessible, providing flexibility in version management.
205
209
 
206
210
  ### `endpoint` Decorator Function Definition
@@ -221,7 +225,7 @@ def endpoint(
221
225
  - Uses `API_MIN_VERSION` and `API_MAX_VERSION` from Django settings.
222
226
  - Supports backward compatibility by registering multiple versions if needed.
223
227
  - Ensures that no version lower than `API_MIN_VERSION` is registered.
224
-
228
+
225
229
  Args:
226
230
  postfix (str): The endpoint suffix (e.g., "users" → "api/v1/users").
227
231
  version (Optional[int]): The version of the API. Defaults to None (unversioned).
@@ -238,7 +242,6 @@ def endpoint(
238
242
  """
239
243
  ```
240
244
 
241
-
242
245
  ## Contributing
243
246
 
244
247
  Feel free to open an issue or submit a pull request with any improvements or bug fixes. We appreciate contributions to enhance this package!
@@ -1,4 +1,3 @@
1
-
2
1
  # Django API Versioning
3
2
 
4
3
  [![PyPI version](https://badge.fury.io/py/django-api-versioning.svg)](https://badge.fury.io/py/django-api-versioning)
@@ -6,7 +5,7 @@
6
5
  [![codecov](https://codecov.io/gh/mojtaba-arvin/django-api-versioning/branch/main/graph/badge.svg)](https://codecov.io/gh/mojtaba-arvin/django-api-versioning)
7
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
7
 
9
- **Django API Versioning** is a powerful and flexible library for managing API versioning in Django projects. It allows you to easily define and manage different versions of your API endpoints using decorators, ensuring backward compatibility and clean code organization.
8
+ **Django API Versioning** is a powerful and flexible library for managing [API versioning in Django](https://github.com/mojtaba-arvin/django-api-versioning) projects. It allows you to easily define and manage different versions of your API endpoints using decorators, ensuring backward compatibility and clean code organization.
10
9
 
11
10
  ## Features
12
11
 
@@ -19,7 +18,7 @@
19
18
 
20
19
  ## Installation
21
20
 
22
- You can install Django API Versioning via pip:
21
+ You can [install Django API Versioning](https://pypi.org/project/django-api-versioning/) via pip:
23
22
 
24
23
  ```bash
25
24
  pip install django-api-versioning
@@ -73,7 +72,6 @@ or you have already have a `ROOT_URLCONF` in settings, you only need to import t
73
72
 
74
73
  The `endpoint` decorator can be used in both function-based views (FBVs) and class-based views (CBVs). It's also fully compatible with `Django Rest Framework (DRF)`. The decorator allows you to define versioning for your API views and supports backward compatibility by default and you don't need to pass `backward=True` flag to the `endpoint` decorator.
75
74
 
76
-
77
75
  #### Example for Function-Based Views (FBVs):
78
76
 
79
77
  ```python
@@ -88,6 +86,7 @@ def users_view(request):
88
86
  In this example, the `users_view` function is decorated with the endpoint decorator. This specifies that the view is accessible under version `2` of the API and **supports backward compatibility**. The `backward=True` flag as default ensures that users can also access the previous version (version `1`) at `/api/v1/account_app/users`.
89
87
 
90
88
  #### Example for Class-Based Views (CBVs):
89
+
91
90
  For class-based views, you can apply the decorator to methods such as `get`, `post`, or any other HTTP method you need to handle. Here’s an example:
92
91
 
93
92
  ```python
@@ -108,7 +107,6 @@ class UsersView(View):
108
107
 
109
108
  If you have already installed [Django Rest Framework](https://www.django-rest-framework.org/#installation), the `endpoint` decorator can be easily applied to APIView or viewsets. Here’s an example with a DRF APIView:
110
109
 
111
-
112
110
  ```python
113
111
  from rest_framework.views import APIView
114
112
  from rest_framework.response import Response
@@ -122,25 +120,26 @@ class UsersAPIView(APIView):
122
120
  ```
123
121
 
124
122
  #### URL Generation Based on Versioning:
123
+
125
124
  Once the decorator is applied, the URLs for your API will be generated based on the version specified in the decorator. For example, if the `API_MIN_VERSION` in your settings.py is set to `1` and the version in the decorator is set to `2`, the following URLs will be available:
126
125
 
127
- * `/api/v1/account_app/users`
128
- * `/api/v2/account_app/users`
126
+ - `/api/v1/account_app/users`
127
+ - `/api/v2/account_app/users`
129
128
 
130
129
  The `API_MIN_VERSION` setting ensures that users can access the API using different versions, providing backward compatibility. You can adjust which versions are considered valid by modifying the `API_MIN_VERSION` and `version` numbers in the decorators.
131
130
 
132
131
  #### Additional Configuration Options:
133
132
 
134
133
  **Without `app_name`:** If you don't pass `app_name` in the decorator, like this:
134
+
135
135
  ```python
136
136
  @endpoint("users", version=2, view_name="users_list_api")
137
137
  ```
138
138
 
139
139
  The generated URLs will be:
140
140
 
141
- * `/api/v1/users`
142
- * `/api/v2/users`
143
-
141
+ - `/api/v1/users`
142
+ - `/api/v2/users`
144
143
 
145
144
  **Without `version`:** If you don't pass `version` in the decorator, like this:
146
145
 
@@ -150,7 +149,7 @@ The generated URLs will be:
150
149
 
151
150
  API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for that view. The only URL generated will be:
152
151
 
153
- * `/users`
152
+ - `/users`
154
153
 
155
154
  **Setting `backward=False`:** By default, the `backward` parameter is set to `True`, which ensures backward compatibility. If you explicitly set `backward=False`, like this:
156
155
 
@@ -160,7 +159,7 @@ API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for
160
159
 
161
160
  The generated URL will be only version 2:
162
161
 
163
- * `api/v2/users`
162
+ - `api/v2/users`
164
163
 
165
164
  4. Run the Server:
166
165
 
@@ -169,16 +168,21 @@ python manage.py runserver
169
168
  ```
170
169
 
171
170
  ## Notes
171
+
172
172
  ### 1. `API_BASE_PATH` in settings Must Include ‍‍`{version}`:
173
+
173
174
  The `API_BASE_PATH` should always include `{version}` to ensure proper API versioning. This is important for correctly mapping API routes to different versions.
174
175
 
175
176
  ### 2. Using `app_name` in the `endpoint` decorator:
177
+
176
178
  It's recommended to fill in the `app_name` in the `endpoint` decorator to make the API URLs **more unique and organized**. This ensures that the routes are scoped under the correct app, avoiding potential conflicts and making them easier to manage.
177
179
 
178
180
  ### 3. Views with Version Less Than `API_MIN_VERSION` Are Automatically Ignored:
181
+
179
182
  Any view whose `version` is less than the `API_MIN_VERSION` will be automatically ignored. This means clients will no longer have access to these older versions, **without the need to manually edit or remove code**. This is handled automatically by the package.
180
183
 
181
184
  ### 4. URLs for Versions Between `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION`:
185
+
182
186
  Endpoints that have versions within the range defined by `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION` will always have a corresponding URL generated. This ensures that only valid versions will be accessible, providing flexibility in version management.
183
187
 
184
188
  ### `endpoint` Decorator Function Definition
@@ -199,7 +203,7 @@ def endpoint(
199
203
  - Uses `API_MIN_VERSION` and `API_MAX_VERSION` from Django settings.
200
204
  - Supports backward compatibility by registering multiple versions if needed.
201
205
  - Ensures that no version lower than `API_MIN_VERSION` is registered.
202
-
206
+
203
207
  Args:
204
208
  postfix (str): The endpoint suffix (e.g., "users" → "api/v1/users").
205
209
  version (Optional[int]): The version of the API. Defaults to None (unversioned).
@@ -216,7 +220,6 @@ def endpoint(
216
220
  """
217
221
  ```
218
222
 
219
-
220
223
  ## Contributing
221
224
 
222
225
  Feel free to open an issue or submit a pull request with any improvements or bug fixes. We appreciate contributions to enhance this package!
@@ -20,10 +20,16 @@ def endpoint(
20
20
  - Ensures that no version lower than `API_MIN_VERSION` is registered.
21
21
 
22
22
  Args:
23
- postfix (str): The endpoint suffix (e.g., "users" → "api/v1/users").
24
- version (Optional[int]): The version of the API. Defaults to None (unversioned).
25
- backward (bool): If True, registers routes for all versions from `API_MIN_VERSION` up to the current version, which is less than or equal to `API_MAX_VERSION`. Defaults to True.
26
- app_name (Optional[str]): The app name to be prefixed to the route.
23
+ postfix (str): The endpoint suffix (e.g., "users" →
24
+ "api/v1/users").
25
+ version (Optional[int]): The version of the API. Defaults
26
+ to None (unversioned).
27
+ backward (bool): If True, registers routes for all versions
28
+ from `API_MIN_VERSION` up to the current
29
+ version, which is less than or equal to
30
+ `API_MAX_VERSION`. Defaults to True.
31
+ app_name (Optional[str]): The app name to be prefixed to
32
+ the route.
27
33
  view_name (Optional[str]): The custom view name for Django.
28
34
 
29
35
  Returns:
@@ -2,7 +2,7 @@ import logging
2
2
  from django.conf import settings
3
3
  from django.core.exceptions import ImproperlyConfigured
4
4
  from dataclasses import dataclass
5
- from typing import Optional
5
+ from typing import Optional, Any
6
6
  from .exceptions import VersionTypeError, VersionRangeError, VersioningError
7
7
 
8
8
  # Initialize logger
@@ -10,14 +10,14 @@ logger = logging.getLogger(__name__)
10
10
 
11
11
  @dataclass
12
12
  class APISettings:
13
-
13
+
14
14
  API_BASE_PATH: str = "api/v{version}/"
15
15
  API_MAX_VERSION: int = 1
16
16
  API_MIN_VERSION: int = 1
17
17
  ROOT_URLCONF: str = 'django_api_versioning.urls'
18
18
 
19
19
  @staticmethod
20
- def get_setting(name: str, default: Optional[any] = None) -> Optional[any]:
20
+ def get_setting(name: str, default: Optional[Any] = None) -> Any:
21
21
  """
22
22
  Reads the setting from Django settings and provides a default if not found.
23
23
  """
@@ -30,9 +30,7 @@ class APISettings:
30
30
 
31
31
  # Ensure that API_BASE_PATH ends with a "/"
32
32
  if not self.API_BASE_PATH.endswith("/"):
33
- logger.warning(
34
- "API_BASE_PATH should end with a '/'. Adding '/' automatically."
35
- )
33
+ logger.warning("API_BASE_PATH should end with a '/'. Adding '/' automatically.")
36
34
  self.API_BASE_PATH += "/"
37
35
 
38
36
  # Validate version settings
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django-api-versioning
3
- Version: 0.1.0
4
- Summary: A powerful and flexible library for managing API versioning in Django projects.
3
+ Version: 0.1.2
4
+ Summary: Django API versioning decorator provides a solution for managing multiple API versions within the Django framework, enabling versioning through URLs with backward compatibility and automatically registering routes.
5
5
  Home-page: https://github.com/mojtaba-arvin/django-api-versioning
6
6
  Author: Mojtaba Arvin
7
7
  Author-email: ArvinDevDay@gmail.com
@@ -15,12 +15,11 @@ Classifier: Development Status :: 3 - Alpha
15
15
  Classifier: Intended Audience :: Developers
16
16
  Classifier: License :: OSI Approved :: MIT License
17
17
  Classifier: Operating System :: OS Independent
18
- Requires-Python: >=3.9
18
+ Requires-Python: >=3.6
19
19
  Description-Content-Type: text/markdown
20
20
  Provides-Extra: dev
21
21
  License-File: LICENSE
22
22
 
23
-
24
23
  # Django API Versioning
25
24
 
26
25
  [![PyPI version](https://badge.fury.io/py/django-api-versioning.svg)](https://badge.fury.io/py/django-api-versioning)
@@ -28,7 +27,7 @@ License-File: LICENSE
28
27
  [![codecov](https://codecov.io/gh/mojtaba-arvin/django-api-versioning/branch/main/graph/badge.svg)](https://codecov.io/gh/mojtaba-arvin/django-api-versioning)
29
28
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
30
29
 
31
- **Django API Versioning** is a powerful and flexible library for managing API versioning in Django projects. It allows you to easily define and manage different versions of your API endpoints using decorators, ensuring backward compatibility and clean code organization.
30
+ **Django API Versioning** is a powerful and flexible library for managing [API versioning in Django](https://github.com/mojtaba-arvin/django-api-versioning) projects. It allows you to easily define and manage different versions of your API endpoints using decorators, ensuring backward compatibility and clean code organization.
32
31
 
33
32
  ## Features
34
33
 
@@ -41,7 +40,7 @@ License-File: LICENSE
41
40
 
42
41
  ## Installation
43
42
 
44
- You can install Django API Versioning via pip:
43
+ You can [install Django API Versioning](https://pypi.org/project/django-api-versioning/) via pip:
45
44
 
46
45
  ```bash
47
46
  pip install django-api-versioning
@@ -95,7 +94,6 @@ or you have already have a `ROOT_URLCONF` in settings, you only need to import t
95
94
 
96
95
  The `endpoint` decorator can be used in both function-based views (FBVs) and class-based views (CBVs). It's also fully compatible with `Django Rest Framework (DRF)`. The decorator allows you to define versioning for your API views and supports backward compatibility by default and you don't need to pass `backward=True` flag to the `endpoint` decorator.
97
96
 
98
-
99
97
  #### Example for Function-Based Views (FBVs):
100
98
 
101
99
  ```python
@@ -110,6 +108,7 @@ def users_view(request):
110
108
  In this example, the `users_view` function is decorated with the endpoint decorator. This specifies that the view is accessible under version `2` of the API and **supports backward compatibility**. The `backward=True` flag as default ensures that users can also access the previous version (version `1`) at `/api/v1/account_app/users`.
111
109
 
112
110
  #### Example for Class-Based Views (CBVs):
111
+
113
112
  For class-based views, you can apply the decorator to methods such as `get`, `post`, or any other HTTP method you need to handle. Here’s an example:
114
113
 
115
114
  ```python
@@ -130,7 +129,6 @@ class UsersView(View):
130
129
 
131
130
  If you have already installed [Django Rest Framework](https://www.django-rest-framework.org/#installation), the `endpoint` decorator can be easily applied to APIView or viewsets. Here’s an example with a DRF APIView:
132
131
 
133
-
134
132
  ```python
135
133
  from rest_framework.views import APIView
136
134
  from rest_framework.response import Response
@@ -144,25 +142,26 @@ class UsersAPIView(APIView):
144
142
  ```
145
143
 
146
144
  #### URL Generation Based on Versioning:
145
+
147
146
  Once the decorator is applied, the URLs for your API will be generated based on the version specified in the decorator. For example, if the `API_MIN_VERSION` in your settings.py is set to `1` and the version in the decorator is set to `2`, the following URLs will be available:
148
147
 
149
- * `/api/v1/account_app/users`
150
- * `/api/v2/account_app/users`
148
+ - `/api/v1/account_app/users`
149
+ - `/api/v2/account_app/users`
151
150
 
152
151
  The `API_MIN_VERSION` setting ensures that users can access the API using different versions, providing backward compatibility. You can adjust which versions are considered valid by modifying the `API_MIN_VERSION` and `version` numbers in the decorators.
153
152
 
154
153
  #### Additional Configuration Options:
155
154
 
156
155
  **Without `app_name`:** If you don't pass `app_name` in the decorator, like this:
156
+
157
157
  ```python
158
158
  @endpoint("users", version=2, view_name="users_list_api")
159
159
  ```
160
160
 
161
161
  The generated URLs will be:
162
162
 
163
- * `/api/v1/users`
164
- * `/api/v2/users`
165
-
163
+ - `/api/v1/users`
164
+ - `/api/v2/users`
166
165
 
167
166
  **Without `version`:** If you don't pass `version` in the decorator, like this:
168
167
 
@@ -172,7 +171,7 @@ The generated URLs will be:
172
171
 
173
172
  API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for that view. The only URL generated will be:
174
173
 
175
- * `/users`
174
+ - `/users`
176
175
 
177
176
  **Setting `backward=False`:** By default, the `backward` parameter is set to `True`, which ensures backward compatibility. If you explicitly set `backward=False`, like this:
178
177
 
@@ -182,7 +181,7 @@ API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for
182
181
 
183
182
  The generated URL will be only version 2:
184
183
 
185
- * `api/v2/users`
184
+ - `api/v2/users`
186
185
 
187
186
  4. Run the Server:
188
187
 
@@ -191,16 +190,21 @@ python manage.py runserver
191
190
  ```
192
191
 
193
192
  ## Notes
193
+
194
194
  ### 1. `API_BASE_PATH` in settings Must Include ‍‍`{version}`:
195
+
195
196
  The `API_BASE_PATH` should always include `{version}` to ensure proper API versioning. This is important for correctly mapping API routes to different versions.
196
197
 
197
198
  ### 2. Using `app_name` in the `endpoint` decorator:
199
+
198
200
  It's recommended to fill in the `app_name` in the `endpoint` decorator to make the API URLs **more unique and organized**. This ensures that the routes are scoped under the correct app, avoiding potential conflicts and making them easier to manage.
199
201
 
200
202
  ### 3. Views with Version Less Than `API_MIN_VERSION` Are Automatically Ignored:
203
+
201
204
  Any view whose `version` is less than the `API_MIN_VERSION` will be automatically ignored. This means clients will no longer have access to these older versions, **without the need to manually edit or remove code**. This is handled automatically by the package.
202
205
 
203
206
  ### 4. URLs for Versions Between `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION`:
207
+
204
208
  Endpoints that have versions within the range defined by `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION` will always have a corresponding URL generated. This ensures that only valid versions will be accessible, providing flexibility in version management.
205
209
 
206
210
  ### `endpoint` Decorator Function Definition
@@ -221,7 +225,7 @@ def endpoint(
221
225
  - Uses `API_MIN_VERSION` and `API_MAX_VERSION` from Django settings.
222
226
  - Supports backward compatibility by registering multiple versions if needed.
223
227
  - Ensures that no version lower than `API_MIN_VERSION` is registered.
224
-
228
+
225
229
  Args:
226
230
  postfix (str): The endpoint suffix (e.g., "users" → "api/v1/users").
227
231
  version (Optional[int]): The version of the API. Defaults to None (unversioned).
@@ -238,7 +242,6 @@ def endpoint(
238
242
  """
239
243
  ```
240
244
 
241
-
242
245
  ## Contributing
243
246
 
244
247
  Feel free to open an issue or submit a pull request with any improvements or bug fixes. We appreciate contributions to enhance this package!
@@ -5,10 +5,16 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="django-api-versioning",
8
- version="0.1.0",
8
+ version="0.1.2",
9
9
  author="Mojtaba Arvin",
10
10
  author_email="ArvinDevDay@gmail.com",
11
- description="A powerful and flexible library for managing API versioning in Django projects.",
11
+ description= (
12
+ "Django API versioning decorator provides a solution "
13
+ "for managing multiple API versions within "
14
+ "the Django framework, enabling versioning "
15
+ "through URLs with backward compatibility "
16
+ "and automatically registering routes."
17
+ ),
12
18
  long_description=long_description,
13
19
  long_description_content_type="text/markdown",
14
20
  url="https://github.com/mojtaba-arvin/django-api-versioning",
@@ -23,7 +29,7 @@ setup(
23
29
  "License :: OSI Approved :: MIT License",
24
30
  "Operating System :: OS Independent",
25
31
  ],
26
- python_requires=">=3.9",
32
+ python_requires=">=3.6",
27
33
  install_requires=[
28
34
  "Django>=3.2",
29
35
  ],