Fast, zero-boilerplate Django REST API framework with pure Python typing!
Project description
No Boilerplate, just rapid Django API ⚡️
Write powerful Django APIs with minimal code. Djapy combines Django's robustness with modern API development practices, giving you a clean, intuitive way to build REST APIs.
@djapify
def get_user(request, username: str) -> UserSchema:
return User.objects.get(username=username)
That's it. No serializers, no viewsets, no boilerplate - just pure Python.
✨ Why Djapy?
Write Django REST APIs that are simple by default, powerful when needed. Djapy works seamlessly with Django's ecosystem while adding modern API features.
# Works perfectly with Django decorators
@cache_page(BASIC_CACHE_1_HOUR)
@djapify
def get_posts(request, search: Optional[str] = None) -> List[PostSchema]:
posts = Post.objects.all()
if search:
posts = posts.filter(title__icontains=search)
return posts
# Need async? Just use async_djapify
@async_djapify
@paginate
async def get_comments(request, post_id: int) -> List[CommentSchema]:
return await Comment.objects.filter(post_id=post_id).aall()
🚀 Key Features
- Zero Boilerplate: Build APIs with pure Python
- Django Native: Works seamlessly with Django's decorators and features
- Type Safety: Full Python type hints with Pydantic
- Async When You Need It: Optional async support for high-performance endpoints
- Smart Authentication: Simple session auth, customizable when needed
- OpenAPI Support: Automatic Swagger documentation
- IDE Friendly: Full intellisense support
🎯 Quick Start
- Install Djapy
pip install djapy
- Create Your First API
from djapy import djapify, Schema
class PostSchema(Schema):
title: str
body: str
author: str
@djapify
def create_post(request, data: PostSchema) -> {201: PostSchema}:
post = Post.objects.create(**data.dict())
return 201, post
# Want caching? Use Django's cache_page
@cache_page(3600)
@djapify
def get_post(request, post_id: int) -> PostSchema:
return Post.objects.get(id=post_id)
🔥 Core Features
1. Simple by Default, Powerful When Needed
# Simple endpoint
@djapify
def get_tag(request, tag_slug: str) -> TagSchema:
return Tags.objects.get(slug=tag_slug)
# Need more power? Add async and pagination
@async_djapify
@paginate
async def get_tag_posts(request, tag_slug: str) -> List[PostSchema]:
tag = await Tags.objects.aget(slug=tag_slug)
return await tag.posts.aall()
2. Works with Django's Ecosystem
from django.views.decorators.cache import cache_page
from django.views.decorators.csrf import csrf_exempt
@cache_page(3600)
@csrf_exempt
@djapify(method="POST")
def create_user(request, data: UserSchema) -> {201: UserSchema}:
user = User.objects.create(**data.dict())
return 201, user
3. Simple Authentication
@djapify(auth=SessionAuth)
def get_profile(request) -> ProfileSchema:
return request.user.profile
# Need custom auth messages?
@djapify(auth=SessionAuth, msg={
"message": "Please log in first",
"redirect": "/login"
})
def protected_view(request) -> ProtectedSchema:
return {"data": "secret"}
4. Type-Safe Responses
@djapify
def get_post(request, post_id: int) -> {
200: PostSchema,
404: MessageSchema
}:
try:
return Post.objects.get(id=post_id)
except Post.DoesNotExist:
return 404, {
"message": "Post not found",
"type": "error"
}
🔄 Migration from DRF
DRF Concept | Djapy Equivalent |
---|---|
ViewSets | Simple function views with @djapify |
Serializers | Pydantic Schema models |
Permissions | Built-in auth system |
Filters | Native Python parameters |
Pagination | @paginate decorator |
📚 Documentation
Visit djapy.io for comprehensive documentation.
🤝 Community & Support
- 📖 Documentation
- 💬 Community
- 🐛 Issue Tracker
- 📦 PyPI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file djapy-0.2.1.tar.gz
.
File metadata
- Download URL: djapy-0.2.1.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
2d9c9c67b8a1ce86953bcc2ab3467982a8b074480c6ed1eb9ab0526318009e39
|
|
MD5 |
57b28975e43d337d4d2ab993aea83506
|
|
BLAKE2b-256 |
6c4e27698075d65ba94fc1bd10d6613c52901521d7067aae1bc3e8e5ce479177
|
File details
Details for the file djapy-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: djapy-0.2.1-py3-none-any.whl
- Upload date:
- Size: 30.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
83903f86a5eacf9310d870d0d8bb32b6330a6fb478c6649038f49ced5f867d8d
|
|
MD5 |
2f8f73b9a70a3b3aaf3c8663ff4107c5
|
|
BLAKE2b-256 |
520e8f79a13c1b92637a1d4764e1cae81b07e9ab79b39fd88fe4bd660c969d0c
|