dflango 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.
Files changed (47) hide show
  1. dflango-0.1.0/LICENSE +21 -0
  2. dflango-0.1.0/MANIFEST.in +6 -0
  3. dflango-0.1.0/PKG-INFO +378 -0
  4. dflango-0.1.0/README.md +338 -0
  5. dflango-0.1.0/dflango/__init__.py +21 -0
  6. dflango-0.1.0/dflango/commands/__init__.py +9 -0
  7. dflango-0.1.0/dflango/commands/command_registration.py +13 -0
  8. dflango-0.1.0/dflango/commands/load_fixtures.py +138 -0
  9. dflango-0.1.0/dflango/commands/start_app.py +58 -0
  10. dflango-0.1.0/dflango/config.py +93 -0
  11. dflango-0.1.0/dflango/core.py +200 -0
  12. dflango-0.1.0/dflango/db.py +10 -0
  13. dflango-0.1.0/dflango/encoders.py +30 -0
  14. dflango-0.1.0/dflango/enum.py +24 -0
  15. dflango-0.1.0/dflango/logging.py +282 -0
  16. dflango-0.1.0/dflango/providers.py +14 -0
  17. dflango-0.1.0/dflango/routes/__init__.py +1 -0
  18. dflango-0.1.0/dflango/routes/route_registry.py +19 -0
  19. dflango-0.1.0/dflango/schemas/__init__.py +11 -0
  20. dflango-0.1.0/dflango/schemas/fields.py +34 -0
  21. dflango-0.1.0/dflango/schemas/model_schemas.py +324 -0
  22. dflango-0.1.0/dflango/schemas/schemas.py +26 -0
  23. dflango-0.1.0/dflango/services/__init__.py +7 -0
  24. dflango-0.1.0/dflango/services/auth.py +9 -0
  25. dflango-0.1.0/dflango/templates/app_template/__init__.py +23 -0
  26. dflango-0.1.0/dflango/templates/app_template/config.py +19 -0
  27. dflango-0.1.0/dflango/templates/app_template/constants.py +14 -0
  28. dflango-0.1.0/dflango/templates/app_template/models/__init__.py +1 -0
  29. dflango-0.1.0/dflango/templates/app_template/models/models.py +16 -0
  30. dflango-0.1.0/dflango/templates/app_template/schemas/__init__.py +1 -0
  31. dflango-0.1.0/dflango/templates/app_template/schemas/schemas.py +18 -0
  32. dflango-0.1.0/dflango/templates/app_template/urls.py +19 -0
  33. dflango-0.1.0/dflango/templates/app_template/views/__init__.py +1 -0
  34. dflango-0.1.0/dflango/templates/app_template/views/views.py +14 -0
  35. dflango-0.1.0/dflango/views/__init__.py +4 -0
  36. dflango-0.1.0/dflango/views/base_view.py +880 -0
  37. dflango-0.1.0/dflango/views/detail_view.py +236 -0
  38. dflango-0.1.0/dflango/views/internal_view.py +99 -0
  39. dflango-0.1.0/dflango/views/list_view.py +384 -0
  40. dflango-0.1.0/dflango.egg-info/PKG-INFO +378 -0
  41. dflango-0.1.0/dflango.egg-info/SOURCES.txt +45 -0
  42. dflango-0.1.0/dflango.egg-info/dependency_links.txt +1 -0
  43. dflango-0.1.0/dflango.egg-info/requires.txt +17 -0
  44. dflango-0.1.0/dflango.egg-info/top_level.txt +1 -0
  45. dflango-0.1.0/pyproject.toml +79 -0
  46. dflango-0.1.0/setup.cfg +4 -0
  47. dflango-0.1.0/setup.py +7 -0
dflango-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hybris Software
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include dflango *.py
5
+ recursive-exclude * __pycache__
6
+ recursive-exclude * *.py[co]
dflango-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,378 @@
1
+ Metadata-Version: 2.4
2
+ Name: dflango
3
+ Version: 0.1.0
4
+ Summary: Django-like utilities for Flask applications
5
+ Author-email: Martino Scarcia <martino.scarcia@hybrissoftware.it>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://git.hybrissoftware.it/hybris/dflango
8
+ Project-URL: Repository, https://git.hybrissoftware.it/hybris/dflango
9
+ Project-URL: Issues, https://git.hybrissoftware.it/hybris/dflango/-/issues
10
+ Keywords: flask,django,web,framework,utilities
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Framework :: Flask
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: flask>=2.0.0
24
+ Requires-Dist: flask-sqlalchemy>=3.0.0
25
+ Requires-Dist: flask-migrate>=4.0.0
26
+ Requires-Dist: flask-cors>=5.0.0
27
+ Requires-Dist: marshmallow>=3.0.0
28
+ Requires-Dist: sqlalchemy>=1.4.0
29
+ Requires-Dist: pyjwt>=2.0.0
30
+ Requires-Dist: click>=8.0.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
33
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
34
+ Requires-Dist: black>=23.0.0; extra == "dev"
35
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
36
+ Requires-Dist: isort>=5.12.0; extra == "dev"
37
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
38
+ Requires-Dist: pre-commit>=3.0.0; extra == "dev"
39
+ Dynamic: license-file
40
+
41
+ # dflango
42
+
43
+ [![Pipeline Status](https://git.hybrissoftware.it/hybris/dflango/badges/main/pipeline.svg)](https://git.hybrissoftware.it/hybris/dflango/-/pipelines)
44
+ [![PyPI version](https://badge.fury.io/py/dflango.svg)](https://badge.fury.io/py/dflango)
45
+ [![Python versions](https://img.shields.io/pypi/pyversions/dflango.svg)](https://pypi.org/project/dflango/)
46
+
47
+ Django-like utilities for Flask applications. This package provides useful tools and patterns inspired by Django to make Flask development more productive.
48
+
49
+ ## Features
50
+
51
+ - **ModelSchema**: Marshmallow schemas with integrated SQLAlchemy model validation
52
+ - **Custom Fields**: Extended Marshmallow fields for common data types
53
+ - **Base Views**: Generic class-based views for list and detail operations
54
+ - **Authentication Services**: JWT-based authentication utilities
55
+ - **Management Commands**: Flask CLI commands for common tasks like loading fixtures
56
+ - **Route Registry**: Centralized route management for better organization
57
+ - **Template Generation**: Helpers for generating template application structures and files
58
+
59
+ ## Installation
60
+
61
+ ### From PyPI (when published)
62
+
63
+ ```bash
64
+ pip install dflango
65
+ ```
66
+
67
+ ### From TestPyPI (for testing)
68
+
69
+ To test the latest version from TestPyPI:
70
+
71
+ ```bash
72
+ pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ dflango
73
+ ```
74
+
75
+ **Note**: The `--extra-index-url` flag is required to install dependencies from the main PyPI repository, as TestPyPI doesn't host all packages.
76
+
77
+ ### From source
78
+
79
+ ```bash
80
+ git clone https://git.hybrissoftware.it/hybris/dflango.git
81
+ cd dflango
82
+ pip install -e .
83
+ ```
84
+
85
+ ### For development
86
+
87
+ ```bash
88
+ pip install -e ".[dev]"
89
+ ```
90
+
91
+ ## Quick Start
92
+
93
+ ```python
94
+ from flask import Flask
95
+ from flask_sqlalchemy import SQLAlchemy
96
+ from dflango import DFlango
97
+
98
+ # Create Flask app
99
+ app = Flask(__name__)
100
+ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
101
+
102
+ # Initialize SQLAlchemy
103
+ db = SQLAlchemy(app)
104
+
105
+ # Initialize DFlango
106
+ dflango = DFlango()
107
+ dflango.init_app(app, db)
108
+
109
+ # Or in one step:
110
+ # dflango = DFlango(app, db)
111
+ ```
112
+
113
+ ### Using ModelSchema
114
+
115
+ ```python
116
+ from dflango import ModelSchema
117
+ from marshmallow import fields
118
+
119
+ class User(db.Model):
120
+ id = db.Column(db.Integer, primary_key=True)
121
+ username = db.Column(db.String(80), unique=True, nullable=False)
122
+ email = db.Column(db.String(120), unique=True, nullable=False)
123
+
124
+ class UserSchema(ModelSchema):
125
+ class Meta:
126
+ model = User
127
+
128
+ username = fields.Str(required=True)
129
+ email = fields.Email(required=True)
130
+
131
+ # Validate and save
132
+ schema = UserSchema()
133
+ schema.validate(request.json)
134
+ user = schema.save()
135
+ ```
136
+
137
+ ### Using Class-Based Views
138
+
139
+ ```python
140
+ from dflango.views import DetailView, ListView
141
+
142
+ class UserDetailView(DetailView):
143
+ model = User
144
+ schema_class = UserSchema
145
+
146
+ class UserListView(ListView):
147
+ model = User
148
+ schema_class = UserSchema
149
+
150
+ # Register routes
151
+ app.add_url_rule('/users/<int:pk>', view_func=UserDetailView.as_view('user_detail'))
152
+ app.add_url_rule('/users', view_func=UserListView.as_view('user_list'))
153
+ ```
154
+
155
+ ### URL Routing with Route Registry
156
+
157
+ You can organize your routes using the `RouteRegistry` class like in the example below:
158
+
159
+ ```python
160
+ # Flask
161
+ from flask import Blueprint
162
+
163
+ # dFlango
164
+ from dflango.routes import RouteRegistry
165
+
166
+ # Views
167
+ from .views.users import UserListView
168
+
169
+ # Create route registry
170
+ class UsersRoutes(RouteRegistry):
171
+ blueprint = Blueprint('users', __name__)
172
+ routes = [
173
+ ('/users', UserListView, 'user_list'),
174
+ ]
175
+ ```
176
+
177
+ ### Using Management Commands
178
+
179
+ You can launch management commands via Flask CLI. For example:
180
+
181
+ ```bash
182
+ flask load-fixtures path/to/fixtures.json
183
+ ```
184
+
185
+ ```bash
186
+ flask start-app myapp
187
+ ```
188
+
189
+ ### Configuration
190
+
191
+ You can configure dflango in three ways:
192
+
193
+ #### 1. Through Flask Config Class (Recommended)
194
+
195
+ ```python
196
+ class Config:
197
+ # Flask settings
198
+ SQLALCHEMY_DATABASE_URI = 'sqlite:///app.db'
199
+ SECRET_KEY = 'your-secret-key'
200
+
201
+ # DFlango settings (prefix with DFLANGO_)
202
+ DFLANGO_DEFAULT_PAGE_SIZE = 50
203
+ DFLANGO_MAX_PAGE_SIZE = 200
204
+ DFLANGO_ENABLE_SOFT_DELETE = True
205
+ DFLANGO_JWT_SECRET_KEY = 'your-jwt-secret'
206
+ DFLANGO_JWT_EXPIRATION_DELTA = 7200 # 2 hours
207
+
208
+ app.config.from_object(Config)
209
+ dflango = DFlango(app, db)
210
+ ```
211
+
212
+ #### 2. Direct app.config update
213
+
214
+ ```python
215
+ app.config.update(
216
+ DFLANGO_DEFAULT_PAGE_SIZE=20,
217
+ DFLANGO_MAX_PAGE_SIZE=100,
218
+ DFLANGO_ENABLE_SOFT_DELETE=True,
219
+ )
220
+ dflango = DFlango(app, db)
221
+ ```
222
+
223
+ #### 3. Programmatically after initialization
224
+
225
+ ```python
226
+ dflango = DFlango(app, db)
227
+
228
+ # Update specific settings
229
+ dflango.update_config(DEFAULT_PAGE_SIZE=30, ENABLE_SOFT_DELETE=False)
230
+
231
+ # Or reload from app.config
232
+ app.config['DFLANGO_DEFAULT_PAGE_SIZE'] = 40
233
+ dflango.reload_config()
234
+ ```
235
+
236
+ ### Available Configuration Options
237
+
238
+ | Config Key | Default | Description |
239
+ |------------|---------|-------------|
240
+ | `DFLANGO_JWT_SECRET_KEY` | `None` | Secret key for JWT encoding/decoding |
241
+ | `DFLANGO_JWT_ALGORITHM` | `'HS256'` | JWT algorithm |
242
+ | `DFLANGO_JWT_EXPIRATION_DELTA` | `3600` | JWT expiration in seconds |
243
+ | `DFLANGO_DEFAULT_PAGE_SIZE` | `20` | Default items per page |
244
+ | `DFLANGO_MAX_PAGE_SIZE` | `100` | Maximum items per page |
245
+ | `DFLANGO_ENABLE_SOFT_DELETE` | `True` | Enable soft delete functionality |
246
+ | `DFLANGO_SOFT_DELETE_FIELD` | `'deleted_at'` | Field name for soft delete timestamp |
247
+ | `DFLANGO_ENABLE_QUERY_LOGGING` | `False` | Enable query logging |
248
+ | `DFLANGO_STRICT_VALIDATION` | `True` | Enable strict validation |
249
+ | `DFLANGO_FIXTURES_PATH` | `'fixtures'` | Path to fixtures directory |
250
+ | `DFLANGO_CORS_ORIGINS` | `'*'` | CORS allowed origins |
251
+ | `DFLANGO_CORS_ALLOW_HEADERS` | `'*'` | CORS allowed headers |
252
+ | `DFLANGO_CORS_SUPPORTS_CREDENTIALS` | `False` | CORS support credentials |
253
+
254
+ ## Requirements
255
+
256
+ - Python >= 3.8
257
+ - Flask >= 2.0.0
258
+ - Flask-SQLAlchemy >= 3.0.0
259
+ - Flask-Migrate >= 4.0.0
260
+ - Flask-Cors >= 5.0.0
261
+ - Marshmallow >= 3.0.0
262
+ - SQLAlchemy >= 1.4.0
263
+ - PyJWT >= 2.0.0
264
+
265
+ ## Development
266
+
267
+ To contribute to dflango:
268
+
269
+ 1. Clone the repository
270
+ 2. Create a virtual environment: `python -m venv venv`
271
+ 3. Activate it: `source venv/bin/activate` (Linux/Mac) or `venv\Scripts\activate` (Windows)
272
+ 4. Install in development mode: `pip install -e ".[dev]"`
273
+ 5. Install pre-commit hooks: `pre-commit install`
274
+
275
+ ### Code Formatting
276
+
277
+ The project uses **black**, **isort**, and **flake8** for code formatting and style.
278
+
279
+ **Format code automatically:**
280
+ ```bash
281
+ # Using the script
282
+ ./format.sh
283
+
284
+ # Or manually
285
+ black dflango/
286
+ isort dflango/
287
+ ```
288
+
289
+ **Check formatting (what CI does):**
290
+ ```bash
291
+ black --check dflango/
292
+ isort --check-only dflango/
293
+ flake8 dflango/
294
+ ```
295
+
296
+ **Pre-commit hooks (automatic formatting before commit):**
297
+ ```bash
298
+ # Install once
299
+ pre-commit install
300
+
301
+ # Run manually on all files
302
+ pre-commit run --all-files
303
+ ```
304
+
305
+ The CI pipeline will **verify** (not fix) that code is properly formatted. If it fails, run `./format.sh` locally and commit the changes.
306
+
307
+ ### Running Tests
308
+
309
+ ```bash
310
+ pytest
311
+ ```
312
+
313
+ ## License
314
+
315
+ This project is licensed under the MIT License - see the LICENSE file for details.
316
+
317
+
318
+
319
+ ## Building and Publishing to PyPI
320
+
321
+ ### Automatic Release with GitLab CI/CD (Recommended)
322
+
323
+ The project uses GitLab CI/CD to automatically publish to PyPI when you create a tag.
324
+
325
+ **Initial setup** (one-time only):
326
+ 1. Create an API token on [pypi.org/manage/account/token](https://pypi.org/manage/account/token/)
327
+ 2. Add the token in GitLab: **Settings** → **CI/CD** → **Variables**
328
+ - Key: `PYPI_TOKEN`
329
+ - Value: Your PyPI token
330
+
331
+ **To release a new version:**
332
+ ```bash
333
+ # 1. Update version in pyproject.toml and dflango/__init__.py
334
+ # 2. Commit and push
335
+ git add .
336
+ git commit -m "Release v0.1.1"
337
+ git push
338
+
339
+ # 3. Create and push the tag
340
+ git tag v0.1.1
341
+ git push origin v0.1.1
342
+
343
+ # 4. The pipeline builds and waits for confirmation on GitLab UI
344
+ # 5. Click Play on GitLab → Pipelines to publish
345
+ ```
346
+
347
+ 📚 **Complete guide**: See [RELEASE.md](RELEASE.md)
348
+
349
+ ---
350
+
351
+ ### Manual Publication (Optional)
352
+
353
+ If you prefer to publish manually:
354
+
355
+ ### Step 1: Install the necessary tools
356
+
357
+ ```bash
358
+ python -m pip install --upgrade build twine
359
+ ```
360
+
361
+ ### Step 2: Clean and build
362
+
363
+ ```bash
364
+ rm -rf dist/ build/ *.egg-info
365
+ python -m build
366
+ ```
367
+
368
+ ### Step 3: Verify and publish
369
+
370
+ ```bash
371
+ twine check dist/*
372
+ twine upload dist/*
373
+ ```
374
+
375
+ Or use the automated script:
376
+ ```bash
377
+ ./publish.sh
378
+ ```