django-ninja-extra2


Namedjango-ninja-extra2 JSON
Version 0.20.7 PyPI version JSON
download
home_pagehttps://github.com/jdiego/django-ninja-extra
SummaryDjango Ninja Extra - Class Based Utility and more for Django Ninja(Fast Django REST framework)
upload_time2024-06-06 21:37:44
maintainerNone
docs_urlNone
authorDiego Saraiva
requires_python>=3.7
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ![Test](https://github.com/eadwinCode/django-ninja-extra/workflows/Test/badge.svg)
[![PyPI version](https://badge.fury.io/py/django-ninja-extra.svg)](https://badge.fury.io/py/django-ninja-extra)
[![PyPI version](https://img.shields.io/pypi/v/django-ninja-extra.svg)](https://pypi.python.org/pypi/django-ninja-extra)
[![PyPI version](https://img.shields.io/pypi/pyversions/django-ninja-extra.svg)](https://pypi.python.org/pypi/django-ninja-extra)
[![PyPI version](https://img.shields.io/pypi/djversions/django-ninja-extra.svg)](https://pypi.python.org/pypi/django-ninja-extra)
[![Codecov](https://img.shields.io/codecov/c/gh/eadwinCode/django-ninja-extra)](https://codecov.io/gh/eadwinCode/django-ninja-extra)
[![Downloads](https://static.pepy.tech/badge/django-ninja-extra)](https://pepy.tech/project/django-ninja-extra)

# Django Ninja Extra

**Django Ninja Extra** package offers a **class-based** approach plus extra functionalities that will speed up your RESTful API development with [**Django Ninja**](https://django-ninja.rest-framework.com)

**Key features:**

All **Django-Ninja** features :
- **Easy**: Designed to be easy to use and intuitive.
- **FAST execution**: Very high performance thanks to **<a href="https://pydantic-docs.helpmanual.io" target="_blank">Pydantic</a>** and **<a href="/async-support/">async support</a>**.
- **Fast to code**: Type hints and automatic docs lets you focus only on business logic.
- **Standards-based**: Based on the open standards for APIs: **OpenAPI** (previously known as Swagger) and **JSON Schema**.
- **Django friendly**: (obviously) has good integration with the Django core and ORM.

Plus **Extra**:
- **Class Based**: Design your APIs in a class based fashion.
- **Permissions**: Protect endpoint(s) at ease with defined permissions and authorizations at route level or controller level.
- **Dependency Injection**: Controller classes supports dependency injection with python [**Injector** ](https://injector.readthedocs.io/en/latest/) or [**django_injector**](https://github.com/blubber/django_injector). Giving you the ability to inject API dependable services to APIController class and utilizing them where needed

---

### Requirements
- Python >= 3.6
- django >= 2.1 
- pydantic >= 1.6 
- Django-Ninja >= 0.16.1

Full documentation, [visit](https://eadwincode.github.io/django-ninja-extra/).

## Installation

```
pip install django-ninja-extra
```
After installation, add `ninja_extra` to your `INSTALLED_APPS`

```Python 
INSTALLED_APPS = [
    ...,
    'ninja_extra',
]
```

## Usage

In your django project next to urls.py create new `api.py` file: 

```Python
from ninja_extra import NinjaExtraAPI, api_controller, http_get

api = NinjaExtraAPI()

# function based definition
@api.get("/add", tags=['Math'])
def add(request, a: int, b: int):
    return {"result": a + b}

#class based definition
@api_controller
class MathAPI:

    @http_get('/subtract',)
    def subtract(self, a: int, b: int):
        """Subtracts a from b"""
        return {"result": a - b}

    @http_get('/divide',)
    def divide(self, a: int, b: int):
        """Divides a by b"""
        return {"result": a / b}
    
    @http_get('/multiple',)
    def multiple(self, a: int, b: int):
        """Multiples a with b"""
        return {"result": a * b}
    
api.register_controllers(
    MathAPI
)
```

Now go to `urls.py` and add the following:

```Python
...
from django.urls import path
from .api import api

urlpatterns = [
    path("admin/", admin.site.urls),
    path("api/", api.urls),  # <---------- !
]

```

### Interactive API docs

Now go to <a href="http://127.0.0.1:8000/api/docs" target="_blank">http://127.0.0.1:8000/api/docs</a>

You will see the automatic interactive API documentation (provided by <a href="https://github.com/swagger-api/swagger-ui" target="_blank">Swagger UI</a>):

![Swagger UI](docs/images/ui_swagger_preview_readme.gif)

## Tutorials
- [django-ninja - Permissions, Controllers & Throttling with django-ninja-extra!](https://www.youtube.com/watch?v=yQqig-c2dd4) - Learn how to use permissions, controllers and throttling with django-ninja-extra
- [BookStore API](https://github.com/eadwinCode/bookstoreapi) - A sample project that demonstrates how to use django-ninja-extra with ninja schema and ninja-jwt

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jdiego/django-ninja-extra",
    "name": "django-ninja-extra2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "Diego Saraiva",
    "author_email": "diegosaraiva@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/55/e8/e2f03b872ae6432403c453627f9cf8aa1a08852cf3d42eac10e15b48df16/django_ninja_extra2-0.20.7.tar.gz",
    "platform": null,
    "description": "![Test](https://github.com/eadwinCode/django-ninja-extra/workflows/Test/badge.svg)\n[![PyPI version](https://badge.fury.io/py/django-ninja-extra.svg)](https://badge.fury.io/py/django-ninja-extra)\n[![PyPI version](https://img.shields.io/pypi/v/django-ninja-extra.svg)](https://pypi.python.org/pypi/django-ninja-extra)\n[![PyPI version](https://img.shields.io/pypi/pyversions/django-ninja-extra.svg)](https://pypi.python.org/pypi/django-ninja-extra)\n[![PyPI version](https://img.shields.io/pypi/djversions/django-ninja-extra.svg)](https://pypi.python.org/pypi/django-ninja-extra)\n[![Codecov](https://img.shields.io/codecov/c/gh/eadwinCode/django-ninja-extra)](https://codecov.io/gh/eadwinCode/django-ninja-extra)\n[![Downloads](https://static.pepy.tech/badge/django-ninja-extra)](https://pepy.tech/project/django-ninja-extra)\n\n# Django Ninja Extra\n\n**Django Ninja Extra** package offers a **class-based** approach plus extra functionalities that will speed up your RESTful API development with [**Django Ninja**](https://django-ninja.rest-framework.com)\n\n**Key features:**\n\nAll **Django-Ninja** features :\n- **Easy**: Designed to be easy to use and intuitive.\n- **FAST execution**: Very high performance thanks to **<a href=\"https://pydantic-docs.helpmanual.io\" target=\"_blank\">Pydantic</a>** and **<a href=\"/async-support/\">async support</a>**.\n- **Fast to code**: Type hints and automatic docs lets you focus only on business logic.\n- **Standards-based**: Based on the open standards for APIs: **OpenAPI** (previously known as Swagger) and **JSON Schema**.\n- **Django friendly**: (obviously) has good integration with the Django core and ORM.\n\nPlus **Extra**:\n- **Class Based**: Design your APIs in a class based fashion.\n- **Permissions**: Protect endpoint(s) at ease with defined permissions and authorizations at route level or controller level.\n- **Dependency Injection**: Controller classes supports dependency injection with python [**Injector** ](https://injector.readthedocs.io/en/latest/) or [**django_injector**](https://github.com/blubber/django_injector). Giving you the ability to inject API dependable services to APIController class and utilizing them where needed\n\n---\n\n### Requirements\n- Python >= 3.6\n- django >= 2.1 \n- pydantic >= 1.6 \n- Django-Ninja >= 0.16.1\n\nFull documentation, [visit](https://eadwincode.github.io/django-ninja-extra/).\n\n## Installation\n\n```\npip install django-ninja-extra\n```\nAfter installation, add `ninja_extra` to your `INSTALLED_APPS`\n\n```Python \nINSTALLED_APPS = [\n    ...,\n    'ninja_extra',\n]\n```\n\n## Usage\n\nIn your django project next to urls.py create new `api.py` file: \n\n```Python\nfrom ninja_extra import NinjaExtraAPI, api_controller, http_get\n\napi = NinjaExtraAPI()\n\n# function based definition\n@api.get(\"/add\", tags=['Math'])\ndef add(request, a: int, b: int):\n    return {\"result\": a + b}\n\n#class based definition\n@api_controller\nclass MathAPI:\n\n    @http_get('/subtract',)\n    def subtract(self, a: int, b: int):\n        \"\"\"Subtracts a from b\"\"\"\n        return {\"result\": a - b}\n\n    @http_get('/divide',)\n    def divide(self, a: int, b: int):\n        \"\"\"Divides a by b\"\"\"\n        return {\"result\": a / b}\n    \n    @http_get('/multiple',)\n    def multiple(self, a: int, b: int):\n        \"\"\"Multiples a with b\"\"\"\n        return {\"result\": a * b}\n    \napi.register_controllers(\n    MathAPI\n)\n```\n\nNow go to `urls.py` and add the following:\n\n```Python\n...\nfrom django.urls import path\nfrom .api import api\n\nurlpatterns = [\n    path(\"admin/\", admin.site.urls),\n    path(\"api/\", api.urls),  # <---------- !\n]\n\n```\n\n### Interactive API docs\n\nNow go to <a href=\"http://127.0.0.1:8000/api/docs\" target=\"_blank\">http://127.0.0.1:8000/api/docs</a>\n\nYou will see the automatic interactive API documentation (provided by <a href=\"https://github.com/swagger-api/swagger-ui\" target=\"_blank\">Swagger UI</a>):\n\n![Swagger UI](docs/images/ui_swagger_preview_readme.gif)\n\n## Tutorials\n- [django-ninja - Permissions, Controllers & Throttling with django-ninja-extra!](https://www.youtube.com/watch?v=yQqig-c2dd4) - Learn how to use permissions, controllers and throttling with django-ninja-extra\n- [BookStore API](https://github.com/eadwinCode/bookstoreapi) - A sample project that demonstrates how to use django-ninja-extra with ninja schema and ninja-jwt\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Django Ninja Extra - Class Based Utility and more for Django Ninja(Fast Django REST framework)",
    "version": "0.20.7",
    "project_urls": {
        "Documentation": "https://eadwincode.github.io/django-ninja-extra/",
        "Homepage": "https://github.com/jdiego/django-ninja-extra"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0ac66e3ccce6c0ba9375338e5c786698b8b021db059d664425da53becfab0695",
                "md5": "6bf77456660aca1caef486a07c5abbea",
                "sha256": "7d9a898f10e75123784c175600cf7b6e34998f51e55f150c35f83bc527de3c56"
            },
            "downloads": -1,
            "filename": "django_ninja_extra2-0.20.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6bf77456660aca1caef486a07c5abbea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 65752,
            "upload_time": "2024-06-06T21:37:39",
            "upload_time_iso_8601": "2024-06-06T21:37:39.225287Z",
            "url": "https://files.pythonhosted.org/packages/0a/c6/6e3ccce6c0ba9375338e5c786698b8b021db059d664425da53becfab0695/django_ninja_extra2-0.20.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "55e8e2f03b872ae6432403c453627f9cf8aa1a08852cf3d42eac10e15b48df16",
                "md5": "33970e62dc6f1f24204187a19326d2de",
                "sha256": "fef21969f4b45e402c4fa1aa4271a624bf7d3e9f4b71bf324b1c2425efff4686"
            },
            "downloads": -1,
            "filename": "django_ninja_extra2-0.20.7.tar.gz",
            "has_sig": false,
            "md5_digest": "33970e62dc6f1f24204187a19326d2de",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7327037,
            "upload_time": "2024-06-06T21:37:44",
            "upload_time_iso_8601": "2024-06-06T21:37:44.242459Z",
            "url": "https://files.pythonhosted.org/packages/55/e8/e2f03b872ae6432403c453627f9cf8aa1a08852cf3d42eac10e15b48df16/django_ninja_extra2-0.20.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-06 21:37:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jdiego",
    "github_project": "django-ninja-extra",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "django-ninja-extra2"
}
        
Elapsed time: 2.22792s