No project description provided
Project description
Django-Jestit Documentation
Django-Jestit is a streamlined set of Django applications and a lightweight REST framework designed to simplify user authentication, authorization, and efficient API testing. This documentation provides descriptions and examples to help you get started quickly.
Why Django-Jestit?
We built Django-Jestit to address the complexity and overhead of existing REST frameworks. Many frameworks are feature-heavy, making them cumbersome for projects that require simplicity, speed, and robust security.
Key Differentiators
-
Lightweight Framework: Django-Jestit is minimalistic, providing an easy way to add REST APIs to your Django models without unnecessary complexity.
-
Built-in Security: Security is integral to Django-Jestit. We offer an alternative to Django's built-in permissions system, automatically protecting your REST APIs and data.
-
Robust Object-Level Permission System: Unlike Django's native model-level permissions, Django-Jestit provides a simple yet robust permission system at the object level. This allows fine-grained control, enabling permissions to be applied to individual objects and extended to both user and group levels.
-
Effortless Integration: Adding REST endpoints to your models is straightforward, enabling rapid development without compromising security or performance.
With Django-Jestit, you get a simple, efficient framework with powerful security features designed for developers who value speed and control.
Table of Contents
- Overview
- Installation
- Authit - Authentication and Authorization
- Jestit - REST framework
- Testit - Testing Suite
- Taskit - Task Runner
- Utilities
Overview
Django-Jestit is a collection of Django-based applications focused on authentication, task management, and testing. These tools are built to enhance development efficiency by providing utilities for common requirements such as user management, token-based authentication, and automated testing.
Installation
pip install django-jestit
Authit
The Authit application manages authentication and authorization using JSON Web Tokens (JWT). It includes models to represent users and groups, and middleware to handle JWT authentication.
JWT Authentication
The JWTAuthenticationMiddleware is a critical component that checks the validity of JWT tokens accompanying HTTP requests.
Example: Middleware Setup
To use the JWT middleware, add it to the middleware list in your Django settings:
MIDDLEWARE = [
# other middleware classes
'authit.middleware.jwt.JWTAuthenticationMiddleware',
]
The middleware checks for JWT tokens in the Authorization header of requests and validates them. If validation fails, it returns an appropriate JSON response with an error message.
Models
Authit's models define the structure of users and groups in the system.
- User: The primary model for user management with fields like
username,email,password, andpermissions. - Group: Represents groups that users can belong to, with a hierarchical structure.
- GroupMember: Manages the membership of users in groups, along with specific group permissions.
Authit REST API
Authit provides RESTful endpoints for managing users and groups. These endpoints leverage Django's request handling framework and custom decorators for URL routing.
Example: User REST API
Users can be managed through RESTful operations. Here’s how you can interact with the user API:
- Create a User: POST to
/api/authit/userwith user data. - Retrieve Users: GET from
/api/authit/userto fetch all users or/api/authit/user/<int:id>for a specific user. - Update a User: PUT to
/api/authit/user/<int:id>with updated user data. - Delete a User: DELETE from
/api/authit/user/<int:id>.
Jestit
Jestit offers a lightweight framework for building REST APIs in Django. It features decorators for automatic URL mapping and serialization tools for data transfer.
URL Decorators
The @jd.URL and other suffix decorators like @jd.GET, @jd.POST, etc., register view functions with specific URL patterns and HTTP methods.
Example: Registering a URL
from jestit.decorators import URL, GET
@URL('myresource')
@GET
def my_view_function(request):
# handle GET request for /myresource
return JsonResponse({'message': 'Hello, Jestit!'})
GraphSerializer
GraphSerializer is a custom serialization mechanism that uses model-defined graphs for data conversion.
Example: Using GraphSerializer
serializer = GraphSerializer(instance=my_model_instance, graph='default')
json_data = serializer.to_json()
This approach allows customization of serialized output by defining graphs in your model's RestMeta class.
Testit
Testit is a testing suite designed to run unit tests for your Django applications efficiently.
Writing Tests
Testit facilitates organizing tests in modules, with decorators to mark and describe each test.
Example: Using the Test Decorator
from testit.helpers import unit_test
@unit_test("Verifying addition logic")
def test_addition():
assert 1 + 1 == 2, "Addition failed"
Running Tests
You can run tests using testit.runner.main() by specifying options.
python jestit/testit/runner.py --module authit --verbose
These tests streamline application and API validation with clear summaries upon completion.
Taskit
Taskit includes the RedisSubscriber class for subscribing to Redis channels. It processes messages asynchronously using multithreading.
Example: Subscribing to a Redis Channel
from redis import Redis
from taskit.runner import RedisSubscriber
def process_task(data):
# handle incoming task
task_type = data['type']
# do something with the task
redis_subscriber = RedisSubscriber(redis_connection=Redis(), channels=['my_channel'])
redis_subscriber.start_listening()
Utilities
Django-Jestit also offers various helper utilities, ranging from logging (logit) to cryptographic operations. Familiarize yourself with these utilities to further refine your project's functionality.
Django-Jestit optimizes the way you handle authentication, build REST APIs, and conduct testing. By using these integrated applications and utilities, you can significantly enhance your development workflow in a Django environment.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_jestit-0.1.15.tar.gz.
File metadata
- Download URL: django_jestit-0.1.15.tar.gz
- Upload date:
- Size: 43.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.10.16 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5999bf6d06ab6e495993c9db5f217617ead5938a755448b041cd09cde78e2e76
|
|
| MD5 |
6b6c929d2e90a2f5ac0c4162595122ea
|
|
| BLAKE2b-256 |
0ff235d40502ffd523eb588c1a6b512bb0fd11946005c48e892bf3c81e5e59a7
|
File details
Details for the file django_jestit-0.1.15-py3-none-any.whl.
File metadata
- Download URL: django_jestit-0.1.15-py3-none-any.whl
- Upload date:
- Size: 60.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.10.16 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ed41d5b8e00e344b8e8358da600a2fc2832750ba9fc2adf0800389babfa4cba
|
|
| MD5 |
ee96b082ddf0093ee120688754e90153
|
|
| BLAKE2b-256 |
4894424b5252400246bd2590d00667170d559dd9cb83b95c90a9991000853c75
|