fastkit-core 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. fastkit_core-0.1.0/PKG-INFO +469 -0
  2. fastkit_core-0.1.0/README.md +421 -0
  3. fastkit_core-0.1.0/fastkit_core/__init__.py +0 -0
  4. fastkit_core-0.1.0/fastkit_core/__version__.py +1 -0
  5. fastkit_core-0.1.0/fastkit_core/config/__init__.py +343 -0
  6. fastkit_core-0.1.0/fastkit_core/config/app.py +7 -0
  7. fastkit_core-0.1.0/fastkit_core/config/database.py +12 -0
  8. fastkit_core-0.1.0/fastkit_core/database/__init__.py +100 -0
  9. fastkit_core-0.1.0/fastkit_core/database/base.py +260 -0
  10. fastkit_core-0.1.0/fastkit_core/database/base_with_timestamps.py +21 -0
  11. fastkit_core-0.1.0/fastkit_core/database/manager.py +248 -0
  12. fastkit_core-0.1.0/fastkit_core/database/mixins.py +402 -0
  13. fastkit_core-0.1.0/fastkit_core/database/repository.py +694 -0
  14. fastkit_core-0.1.0/fastkit_core/database/session.py +628 -0
  15. fastkit_core-0.1.0/fastkit_core/database/translatable.py +402 -0
  16. fastkit_core-0.1.0/fastkit_core/http/__init__.py +39 -0
  17. fastkit_core-0.1.0/fastkit_core/http/dependencies.py +20 -0
  18. fastkit_core-0.1.0/fastkit_core/http/exception_handlers.py +105 -0
  19. fastkit_core-0.1.0/fastkit_core/http/exceptions.py +43 -0
  20. fastkit_core-0.1.0/fastkit_core/http/middleware.py +49 -0
  21. fastkit_core-0.1.0/fastkit_core/http/responses.py +117 -0
  22. fastkit_core-0.1.0/fastkit_core/i18n/__init__.py +26 -0
  23. fastkit_core-0.1.0/fastkit_core/i18n/translation.py +355 -0
  24. fastkit_core-0.1.0/fastkit_core/services/__init__.py +5 -0
  25. fastkit_core-0.1.0/fastkit_core/services/base_crud_service.py +516 -0
  26. fastkit_core-0.1.0/fastkit_core/validation/__init__.py +31 -0
  27. fastkit_core-0.1.0/fastkit_core/validation/base.py +111 -0
  28. fastkit_core-0.1.0/fastkit_core/validation/rules.py +30 -0
  29. fastkit_core-0.1.0/fastkit_core/validation/validators.py +135 -0
  30. fastkit_core-0.1.0/fastkit_core.egg-info/PKG-INFO +469 -0
  31. fastkit_core-0.1.0/fastkit_core.egg-info/SOURCES.txt +45 -0
  32. fastkit_core-0.1.0/fastkit_core.egg-info/dependency_links.txt +1 -0
  33. fastkit_core-0.1.0/fastkit_core.egg-info/requires.txt +27 -0
  34. fastkit_core-0.1.0/fastkit_core.egg-info/top_level.txt +1 -0
  35. fastkit_core-0.1.0/pyproject.toml +168 -0
  36. fastkit_core-0.1.0/setup.cfg +4 -0
  37. fastkit_core-0.1.0/tests/test_config.py +1007 -0
  38. fastkit_core-0.1.0/tests/test_database_base.py +437 -0
  39. fastkit_core-0.1.0/tests/test_database_manager.py +575 -0
  40. fastkit_core-0.1.0/tests/test_database_mixins.py +524 -0
  41. fastkit_core-0.1.0/tests/test_database_repository.py +947 -0
  42. fastkit_core-0.1.0/tests/test_database_session.py +597 -0
  43. fastkit_core-0.1.0/tests/test_database_translatable.py +876 -0
  44. fastkit_core-0.1.0/tests/test_http.py +1000 -0
  45. fastkit_core-0.1.0/tests/test_i18n.py +760 -0
  46. fastkit_core-0.1.0/tests/test_service.py +1017 -0
  47. fastkit_core-0.1.0/tests/test_validation.py +1049 -0
@@ -0,0 +1,469 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastkit-core
3
+ Version: 0.1.0
4
+ Summary: FastKit Core is a lightweight toolkit that adds structure and common patterns to FastAPI.
5
+ Author-email: Codevelo <info@codevelo.io>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/codevelo-pub/fastkit-core/fastkit-core
8
+ Project-URL: Documentation, https://github.com/codevelo-pub/fastkit-core
9
+ Project-URL: Repository, https://github.com/codevelo-pub/fastkit-core
10
+ Project-URL: Issues, https://github.com/codevelo-pub/fastkit-core/issues
11
+ Keywords: fastapi,framework,toolkit,laravel,web,api,crud,database,orm
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Framework :: FastAPI
20
+ Classifier: Topic :: Internet :: WWW/HTTP
21
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ Requires-Dist: fastapi<0.116.0,>=0.115.0
26
+ Requires-Dist: uvicorn[standard]<0.35.0,>=0.34.0
27
+ Requires-Dist: pydantic<3.0.0,>=2.10.0
28
+ Requires-Dist: pydantic-settings<3.0.0,>=2.6.0
29
+ Requires-Dist: sqlalchemy<2.1.0,>=2.0.36
30
+ Requires-Dist: python-dotenv<2.0.0,>=1.0.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=8.3.0; extra == "dev"
33
+ Requires-Dist: pytest-cov>=6.0.0; extra == "dev"
34
+ Requires-Dist: pytest-asyncio>=0.24.0; extra == "dev"
35
+ Requires-Dist: ruff>=0.8.0; extra == "dev"
36
+ Requires-Dist: black>=24.10.0; extra == "dev"
37
+ Requires-Dist: isort>=5.13.0; extra == "dev"
38
+ Requires-Dist: mypy>=1.13.0; extra == "dev"
39
+ Provides-Extra: postgresql
40
+ Requires-Dist: psycopg2-binary>=2.9.10; extra == "postgresql"
41
+ Provides-Extra: mysql
42
+ Requires-Dist: pymysql>=1.1.0; extra == "mysql"
43
+ Requires-Dist: cryptography>=44.0.0; extra == "mysql"
44
+ Provides-Extra: docs
45
+ Requires-Dist: mkdocs>=1.6.0; extra == "docs"
46
+ Requires-Dist: mkdocs-material>=9.5.0; extra == "docs"
47
+ Requires-Dist: mkdocstrings[python]>=0.27.0; extra == "docs"
48
+
49
+ <div align="center">
50
+ <h1>FastKit Core</h1>
51
+
52
+ [![PyPI version](https://badge.fury.io/py/fastkit-core.svg)](https://pypi.org/project/fastkit-core/)
53
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
54
+ [![CI](https://github.com/codevelo-pub/fastkit-core/actions/workflows/tests.yml/badge.svg)](https://github.com/codevelo-pub/fastkit-core/actions/workflows/tests.yml)
55
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
56
+ </div>
57
+
58
+ ---
59
+
60
+ ## What is FastKit Core?
61
+
62
+ **FastKit Core is a lightweight toolkit that adds structure and common patterns to FastAPI.**
63
+
64
+ The software development is an enjoyable and creative experience, so we believe developers should focus on building features, not infrastructure. FastKit Core provides the patterns and structure so you can do exactly that.
65
+
66
+ FastAPI is fast and flexible by design, but it's minimal - you build the structure yourself. FastKit Core provides that structure with production-ready patterns:
67
+
68
+ - **Repository Pattern** for database operations
69
+ - **Service Layer** for business logic
70
+ - **Multi-Language Support** built into models and translation files
71
+ - **Validation** with translated error messages
72
+ - **HTTP Utilities** for consistent API responses
73
+
74
+ Think of it as **FastAPI with batteries included** — inspired by Laravel's DX and Django's patterns, built specifically for FastAPI.
75
+
76
+ **Not a framework. Not a replacement. Just FastAPI with structure.**
77
+
78
+ ---
79
+ ## Who is FastKit Core For?
80
+
81
+ **FastKit Core is built for developers who:**
82
+
83
+ **Are Coming from Laravel or Django**
84
+ - You love the structure and developer experience, but need FastAPI's performance
85
+ - You want familiar concepts (repositories, services, mixins) in modern Python
86
+ - You're tired of rebuilding patterns from scratch in every FastAPI project
87
+
88
+ **Are Building Production Applications**
89
+ - You need consistent, maintainable code structure across your team
90
+ - You want proven patterns, not experimental approaches
91
+ - You're building multi-language applications or complex business logic
92
+
93
+ **Are New to FastAPI Architecture**
94
+ - FastAPI's minimal structure leaves you wondering where to put things
95
+ - You need guidance on organizing business logic and database operations
96
+ - You want to learn best practices from day one
97
+
98
+ **Are Leading Development Teams**
99
+ - You need to standardize how your team builds FastAPI applications
100
+ - You want faster onboarding and more consistent code reviews
101
+ - You're tired of every developer having their own architectural approach
102
+
103
+ **FastKit Core is not for you if:**
104
+ - You prefer building everything from scratch and don't want any structure
105
+ - You're building simple CRUD APIs with no business logic
106
+ - You only need basic FastAPI features (FastAPI alone is perfect for this!)
107
+ ---
108
+
109
+ ## Why FastKit Core?
110
+
111
+ ### The Problem
112
+
113
+ When building FastAPI applications, you quickly face questions:
114
+
115
+ - How should I structure my project?
116
+ - Where do repositories go? Do I even need them?
117
+ - How do I organize business logic?
118
+ - How do I handle multi-language content in my models?
119
+ - How do I format validation errors consistently?
120
+ - How do I standardize API responses?
121
+
122
+ Every team solves these differently, leading to inconsistent codebases.
123
+
124
+ ### The Solution
125
+
126
+ FastKit Core provides **battle-tested patterns** so you don't reinvent the wheel:
127
+
128
+ - **10x Faster Development**
129
+ Stop building infrastructure. Start building features.
130
+
131
+ - **Production Ready**
132
+ Patterns proven in real-world applications, not experimental code.
133
+
134
+ - **Unique Features**
135
+ TranslatableMixin for effortless multi-language models.
136
+
137
+ - **Zero Vendor Lock-in**
138
+ Pure FastAPI underneath. Use what you need, skip what you don't.
139
+
140
+ - **Great Developer Experience**
141
+ Inspired by Laravel and Django, built for FastAPI's modern Python.
142
+
143
+ ### The Result
144
+ ```python
145
+ # Before FastKit: 100+ lines of boilerplate
146
+ # With FastKit: 10 lines
147
+
148
+ class Article(BaseWithTimestamps, IntIdMixin, TranslatableMixin):
149
+ __translatable__ = ['title', 'content']
150
+ title: Mapped[dict] = mapped_column(JSON)
151
+ content: Mapped[dict] = mapped_column(JSON)
152
+
153
+ # Multi-language support just works
154
+ article.title = "Hello"
155
+ article.set_locale('es')
156
+ article.title = "Hola"
157
+ ```
158
+
159
+ ---
160
+
161
+ ## Quick Start
162
+
163
+ Get up and running in 5 minutes:
164
+
165
+ ### Installation
166
+ ```bash
167
+ pip install fastkit-core
168
+ ```
169
+
170
+ ### Your First FastKit Application
171
+ ```python
172
+ from fastapi import FastAPI, Depends
173
+ from sqlalchemy.orm import Session
174
+ from fastkit_core.database import BaseWithTimestamps, Repository, get_db, IntIdMixin
175
+ from fastkit_core.services import BaseCrudService
176
+ from fastkit_core.validation import BaseSchema
177
+ from fastkit_core.http import success_response, register_exception_handlers
178
+ from fastkit_core.i18n import _
179
+ from pydantic import EmailStr
180
+
181
+ # 1. Define your model
182
+ class User(BaseWithTimestamps, IntIdMixin):
183
+ email: Mapped[str]
184
+ name: Mapped[str]
185
+
186
+ # 2. Define your schema
187
+ class UserCreate(BaseSchema, IntIdMixin):
188
+ email: EmailStr
189
+ name: str
190
+
191
+ # 3. Define your service (business logic)
192
+ class UserService(BaseCrudService[User, UserCreate, UserCreate]):
193
+ def validate_create(self, data):
194
+ if self.exists(email=data.email):
195
+ raise ValueError(_('validation.registration.email_is_taken'))
196
+
197
+ # 4. Create your API
198
+ app = FastAPI()
199
+ register_exception_handlers(app)
200
+
201
+ @app.post("/users")
202
+ def create_user(data: UserCreate, db: Session = Depends(get_db)):
203
+ service = UserService(Repository(User, db))
204
+ user = service.create(data)
205
+ return success_response(data=user.to_dict())
206
+
207
+ @app.get("/users")
208
+ def list_users(db: Session = Depends(get_db)):
209
+ service = UserService(Repository(User, db))
210
+ users = service.get_all()
211
+ return success_response(data=[u.to_dict() for u in users])
212
+ ```
213
+
214
+ **That's it!** You have a fully functional API with:
215
+ - Validation with proper, translatable error messages
216
+ - Business logic separated in services
217
+ - Repository pattern for database
218
+ - Consistent response formatting
219
+ - Timestamps automatically managed
220
+
221
+ **[See full documentation →](https://fastkit.codevelo.io)**
222
+
223
+ ---
224
+
225
+ ## Core Modules
226
+
227
+ FastKit Core provides six integrated modules:
228
+
229
+ ### Configuration
230
+
231
+ Manage application configuration with environment support.
232
+ ```python
233
+ from fastkit_core.config import config
234
+
235
+ # Load from config files or environment variables
236
+ db_host = config('database.HOST', 'localhost')
237
+ debug_mode = config('app.DEBUG', False)
238
+ ```
239
+
240
+ **Features:**
241
+ - Multi-environment support (dev, test, prod)
242
+ - `.env` file loading with auto-discovery
243
+ - Dot notation access
244
+ - Type casting (strings to bool, int, float)
245
+
246
+ **[Configuration Documentation →](https://fastkit.codevelo.io/modules/config)**
247
+
248
+ ---
249
+
250
+ ### Database
251
+
252
+ Repository pattern with powerful mixins for common use cases.
253
+ ```python
254
+ from fastkit_core.database import (
255
+ BaseWithTimestamps,
256
+ TranslatableMixin,
257
+ SoftDeleteMixin,
258
+ Repository
259
+ )
260
+
261
+ # Rich model with automatic features
262
+ class Article(BaseWithTimestamps, IntIdMixin, TranslatableMixin, SoftDeleteMixin):
263
+ __translatable__ = ['title', 'content']
264
+
265
+ title: Mapped[dict] = mapped_column(JSON)
266
+ content: Mapped[dict] = mapped_column(JSON)
267
+ author_id: Mapped[int]
268
+
269
+ # Django-style queries
270
+ articles = Repository(Article, session).filter(
271
+ author_id__in=[1, 2, 3],
272
+ created_at__gte=datetime(2024, 1, 1),
273
+ _order_by='-created_at'
274
+ )
275
+
276
+ # Multi-language support
277
+ article.title = "Hello World"
278
+ article.set_locale('es')
279
+ article.title = "Hola Mundo"
280
+ print(article.to_dict(locale='es'))
281
+ ```
282
+
283
+ **Features:**
284
+ - Repository pattern with Django-style operators
285
+ - TranslatableMixin for multi-language models
286
+ - SoftDeleteMixin for data retention
287
+ - TimestampsMixin for automatic timestamps
288
+ - UUIDMixin, SlugMixin, PublishableMixin
289
+ - Multi-connection support with read replicas
290
+
291
+ **[Database Documentation →](https://fastkit.codevelo.io/modules/database)**
292
+
293
+ ---
294
+
295
+ ### Services
296
+
297
+ Service layer with validation hooks and lifecycle management.
298
+ ```python
299
+ from fastkit_core.services import BaseCrudService
300
+
301
+ class UserService(BaseCrudService[User, UserCreate, UserUpdate]):
302
+
303
+ def validate_create(self, data: UserCreate):
304
+ """Custom validation before creation"""
305
+ if self.exists(email=data.email):
306
+ raise ValueError("Email already exists")
307
+
308
+ def before_create(self, data: dict) -> dict:
309
+ """Modify data before saving"""
310
+ data['password'] = hash_password(data['password'])
311
+ return data
312
+
313
+ def after_create(self, instance: User):
314
+ """Actions after creation"""
315
+ send_welcome_email(instance.email)
316
+
317
+ # Use in routes
318
+ service = UserService(Repository(User, session))
319
+ user = service.create(user_data) # All hooks run automatically
320
+ ```
321
+
322
+ **Features:**
323
+ - BaseCrudService with all CRUD operations
324
+ - Validation hooks
325
+ - Lifecycle hooks (before/after create, update, delete)
326
+ - Transaction management
327
+ - Pagination support
328
+ - Seamless repository integration
329
+
330
+ **[Services Documentation →](https://fastkit.codevelo.io/modules/services)**
331
+
332
+ ---
333
+
334
+ ### Internationalization (i18n)
335
+
336
+ Manage translations with Laravel-style helpers.
337
+ ```python
338
+ from fastkit_core.i18n import _, set_locale
339
+
340
+ # translations/en.json
341
+ # {
342
+ # "messages": {
343
+ # "welcome": "Welcome, {name}!",
344
+ # "goodbye": "Goodbye!"
345
+ # }
346
+ # }
347
+
348
+ set_locale('en')
349
+ print(_('messages.welcome', name='John')) # "Welcome, John!"
350
+
351
+ set_locale('es')
352
+ print(_('messages.welcome', name='Juan')) # "¡Bienvenido, Juan!"
353
+ ```
354
+
355
+ **Features:**
356
+ - JSON-based translations
357
+ - Pythonic `_()` helper (follows gettext standard)
358
+ - Variable replacement
359
+ - Locale context (shared with TranslatableMixin)
360
+ - Fallback support
361
+ - Middleware integration
362
+
363
+ **[i18n Documentation →](https://fastkit.codevelo.io/modules/i18n)**
364
+
365
+ ---
366
+
367
+ ### Validation
368
+
369
+ Pydantic schemas with translated error messages and reusable validators.
370
+ ```python
371
+ from pydantic import EmailStr
372
+ from fastkit_core.validation import (
373
+ BaseSchema,
374
+ PasswordValidatorMixin,
375
+ UsernameValidatorMixin
376
+ )
377
+
378
+ class UserCreate(BaseSchema, PasswordValidatorMixin, UsernameValidatorMixin):
379
+ email: EmailStr
380
+ username: str # Validated by UsernameValidatorMixin
381
+ password: str # Validated by PasswordValidatorMixin
382
+
383
+ # Validation errors are automatically translated
384
+ set_locale('es')
385
+ try:
386
+ user = UserCreate(email="invalid", password="weak")
387
+ except ValidationError as e:
388
+ errors = BaseSchema.format_errors(e)
389
+ # Returns: {"email": ["Must be valid..."], "password": ["Must be at least..."]}
390
+ ```
391
+
392
+ **Features:**
393
+ - BaseSchema with Laravel-style error formatting
394
+ - Automatic translation of error messages
395
+ - Reusable validation mixins
396
+ - Customizable error messages per schema
397
+ - Field validation rules
398
+ - Pydantic v2 compatible
399
+
400
+ **[Validation Documentation →](https://fastkit.codevelo.io/modules/validation)**
401
+
402
+ ---
403
+
404
+ ### HTTP
405
+
406
+ Standard response formatting and exception handling.
407
+ ```python
408
+ from fastkit_core.http import (
409
+ success_response,
410
+ paginated_response,
411
+ NotFoundException,
412
+ register_exception_handlers
413
+ )
414
+
415
+ # Register handlers once
416
+ app = FastAPI()
417
+ register_exception_handlers(app)
418
+
419
+ @app.get("/users/{user_id}")
420
+ def get_user(user_id: int):
421
+ user = service.find(user_id)
422
+ if not user:
423
+ raise NotFoundException(f"User {user_id} not found")
424
+
425
+ return success_response(data=user.to_dict())
426
+
427
+ @app.get("/users")
428
+ def list_users(page: int = 1):
429
+ users, pagination = service.paginate(page=page, per_page=20)
430
+ return paginated_response(
431
+ items=[u.to_dict() for u in users],
432
+ pagination=pagination
433
+ )
434
+ ```
435
+
436
+ **Features:**
437
+ - Standard response formatters
438
+ - Automatic exception handling
439
+ - Custom exceptions
440
+ - Middleware (RequestID, Locale detection)
441
+ - Pagination helpers
442
+ - CORS configuration
443
+
444
+ **[HTTP Documentation →](https://fastkit.codevelo.io/modules/http)**
445
+
446
+ ---
447
+
448
+ ## Documentation
449
+
450
+ Complete guides, tutorials, and API reference:
451
+ **[fastkit.codevelo.io](https://fastkit.codevelo.io)**
452
+
453
+ ---
454
+
455
+ ## Contributing
456
+
457
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md).
458
+
459
+ ---
460
+
461
+ ## License
462
+
463
+ FastKit Core is open-source software licensed under the [MIT License](https://opensource.org/license/MIT).
464
+
465
+ ---
466
+
467
+ ## Built by CodeVelo
468
+
469
+ FastKit is developed and maintained by [Codevelo](https://codevelo.io) for the FastAPI community.