django-jestit


Namedjango-jestit JSON
Version 0.1.11 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2025-02-19 19:39:43
maintainerNone
docs_urlNone
authorIan Starnes
requires_python<4.0,>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

1. [Overview](#overview)
2. [Installation](#installation)
3. [Authit - Authentication and Authorization](#authit)
   - [JWT Authentication Middleware](#jwt-authentication)
   - [Models](#models)
   - [REST API](#authit-rest-api)
4. [Jestit - REST framework](#jestit)
   - [URL Decorators](#url-decorators)
   - [GraphSerializer](#graphserializer)
5. [Testit - Testing Suite](#testit)
   - [Writing Tests](#writing-tests)
   - [Running Tests](#running-tests)
6. [Taskit - Task Runner](#taskit)
7. [Utilities](#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

```bash
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:

```python
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`, and `permissions`.
- **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/user` with user data.
- **Retrieve Users**: GET from `/api/authit/user` to 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**

```python
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**

```python
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**

```python
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.

```bash
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**

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "django-jestit",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Ian Starnes",
    "author_email": "ian@311labs.com",
    "download_url": "https://files.pythonhosted.org/packages/d2/1c/aeb164029b1e1431253668fcb2dd698b41f7c7090cf01b7acea62992d6a3/django_jestit-0.1.11.tar.gz",
    "platform": null,
    "description": "# Django-Jestit Documentation\n\nDjango-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.\n\n## Why Django-Jestit?\n\nWe 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.\n\n## Key Differentiators\n\n- **Lightweight Framework:** Django-Jestit is minimalistic, providing an easy way to add REST APIs to your Django models without unnecessary complexity.\n\n- **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.\n\n- **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.\n\n- **Effortless Integration:** Adding REST endpoints to your models is straightforward, enabling rapid development without compromising security or performance.\n\nWith Django-Jestit, you get a simple, efficient framework with powerful security features designed for developers who value speed and control.\n## Table of Contents\n\n1. [Overview](#overview)\n2. [Installation](#installation)\n3. [Authit - Authentication and Authorization](#authit)\n   - [JWT Authentication Middleware](#jwt-authentication)\n   - [Models](#models)\n   - [REST API](#authit-rest-api)\n4. [Jestit - REST framework](#jestit)\n   - [URL Decorators](#url-decorators)\n   - [GraphSerializer](#graphserializer)\n5. [Testit - Testing Suite](#testit)\n   - [Writing Tests](#writing-tests)\n   - [Running Tests](#running-tests)\n6. [Taskit - Task Runner](#taskit)\n7. [Utilities](#utilities)\n\n## Overview\n\nDjango-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.\n\n## Installation\n\n```bash\npip install django-jestit\n```\n\n## Authit\n\nThe **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.\n\n### JWT Authentication\n\nThe `JWTAuthenticationMiddleware` is a critical component that checks the validity of JWT tokens accompanying HTTP requests.\n\n**Example: Middleware Setup**\n\nTo use the JWT middleware, add it to the middleware list in your Django settings:\n\n```python\nMIDDLEWARE = [\n    # other middleware classes\n    'authit.middleware.jwt.JWTAuthenticationMiddleware',\n]\n```\n\nThe 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.\n\n### Models\n\nAuthit's models define the structure of users and groups in the system.\n\n- **User**: The primary model for user management with fields like `username`, `email`, `password`, and `permissions`.\n- **Group**: Represents groups that users can belong to, with a hierarchical structure.\n- **GroupMember**: Manages the membership of users in groups, along with specific group permissions.\n\n### Authit REST API\n\nAuthit provides RESTful endpoints for managing users and groups. These endpoints leverage Django's request handling framework and custom decorators for URL routing.\n\n**Example: User REST API**\n\nUsers can be managed through RESTful operations. Here\u2019s how you can interact with the user API:\n\n- **Create a User**: POST to `/api/authit/user` with user data.\n- **Retrieve Users**: GET from `/api/authit/user` to fetch all users or `/api/authit/user/<int:id>` for a specific user.\n- **Update a User**: PUT to `/api/authit/user/<int:id>` with updated user data.\n- **Delete a User**: DELETE from `/api/authit/user/<int:id>`.\n\n## Jestit\n\nJestit offers a lightweight framework for building REST APIs in Django. It features decorators for automatic URL mapping and serialization tools for data transfer.\n\n### URL Decorators\n\nThe `@jd.URL` and other suffix decorators like `@jd.GET`, `@jd.POST`, etc., register view functions with specific URL patterns and HTTP methods.\n\n**Example: Registering a URL**\n\n```python\nfrom jestit.decorators import URL, GET\n\n@URL('myresource')\n@GET\ndef my_view_function(request):\n    # handle GET request for /myresource\n    return JsonResponse({'message': 'Hello, Jestit!'})\n```\n\n### GraphSerializer\n\n`GraphSerializer` is a custom serialization mechanism that uses model-defined graphs for data conversion.\n\n**Example: Using GraphSerializer**\n\n```python\nserializer = GraphSerializer(instance=my_model_instance, graph='default')\njson_data = serializer.to_json()\n```\n\nThis approach allows customization of serialized output by defining graphs in your model's `RestMeta` class.\n\n## Testit\n\nTestit is a testing suite designed to run unit tests for your Django applications efficiently.\n\n### Writing Tests\n\nTestit facilitates organizing tests in modules, with decorators to mark and describe each test.\n\n**Example: Using the Test Decorator**\n\n```python\nfrom testit.helpers import unit_test\n\n@unit_test(\"Verifying addition logic\")\ndef test_addition():\n    assert 1 + 1 == 2, \"Addition failed\"\n```\n\n### Running Tests\n\nYou can run tests using `testit.runner.main()` by specifying options.\n\n```bash\npython jestit/testit/runner.py --module authit --verbose\n```\n\nThese tests streamline application and API validation with clear summaries upon completion.\n\n## Taskit\n\nTaskit includes the `RedisSubscriber` class for subscribing to Redis channels. It processes messages asynchronously using multithreading.\n\n**Example: Subscribing to a Redis Channel**\n\n```python\nfrom redis import Redis\nfrom taskit.runner import RedisSubscriber\n\ndef process_task(data):\n    # handle incoming task\n    task_type = data['type']\n    # do something with the task\n\nredis_subscriber = RedisSubscriber(redis_connection=Redis(), channels=['my_channel'])\nredis_subscriber.start_listening()\n```\n\n## Utilities\n\nDjango-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.\n\n---\n\nDjango-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.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": null,
    "version": "0.1.11",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e44a078428daef7b0df52b1251692a622ef76d967b2e61360e9cbd88c9ebdd52",
                "md5": "bd8ff2c8b1788588699a14e245910cb4",
                "sha256": "0eb17ea0f24a4e6f6397553a21865b577dff77f9295dcfdb4ebdbe98e8e6afdb"
            },
            "downloads": -1,
            "filename": "django_jestit-0.1.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bd8ff2c8b1788588699a14e245910cb4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 52677,
            "upload_time": "2025-02-19T19:39:41",
            "upload_time_iso_8601": "2025-02-19T19:39:41.664011Z",
            "url": "https://files.pythonhosted.org/packages/e4/4a/078428daef7b0df52b1251692a622ef76d967b2e61360e9cbd88c9ebdd52/django_jestit-0.1.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d21caeb164029b1e1431253668fcb2dd698b41f7c7090cf01b7acea62992d6a3",
                "md5": "5f784467406774c73ad7edeaddb95ff6",
                "sha256": "85748bafb77c819445a85067318199d871271e8660fa047bdd96b89dfed1f210"
            },
            "downloads": -1,
            "filename": "django_jestit-0.1.11.tar.gz",
            "has_sig": false,
            "md5_digest": "5f784467406774c73ad7edeaddb95ff6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 38172,
            "upload_time": "2025-02-19T19:39:43",
            "upload_time_iso_8601": "2025-02-19T19:39:43.354468Z",
            "url": "https://files.pythonhosted.org/packages/d2/1c/aeb164029b1e1431253668fcb2dd698b41f7c7090cf01b7acea62992d6a3/django_jestit-0.1.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-19 19:39:43",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "django-jestit"
}
        
Elapsed time: 1.77179s