Django Ninja is a web framework for building APIs with Django and Python 3.6+ type hints.

Overview

Fast to learn, fast to code, fast to run

Test Coverage PyPI version

Django Ninja - Fast Django REST Framework

Django Ninja is a web framework for building APIs with Django and Python 3.6+ type hints.

Key features:

  • Easy: Designed to be easy to use and intuitive.
  • FAST execution: Very high performance thanks to Pydantic and async support.
  • 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.
  • Production ready: Used by multiple companies on live projects (If you use django-ninja and would like to publish your feedback, please email [email protected]).

Django Ninja REST Framework

Documentation: https://django-ninja.rest-framework.com


Installation

pip install django-ninja

Usage

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

from ninja import NinjaAPI

api = NinjaAPI()


@api.get("/add")
def add(request, a: int, b: int):
    return {"result": a + b}

Now go to urls.py and add the following:

...
from .api import api

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

That's it !

Now you've just created an API that:

  • receives an HTTP GET request at /api/add
  • takes, validates and type-casts GET parameters a and b
  • decodes the result to JSON
  • generates an OpenAPI schema for defined operation

Interactive API docs

Now go to http://127.0.0.1:8000/api/docs

You will see the automatic interactive API documentation (provided by Swagger UI):

Swagger UI

What next?

Comments
  • Unable to upload file (always get 'field required' message)

    Unable to upload file (always get 'field required' message)

    Hi @vitalik, I'm trying to upload a file but it's always getting a "field required" message.

    Screenshot from 2021-08-15 08-55-14

    Handler:

    FileParam = File
    def file_create(request: HttpRequest,
            name: str = FileParam(..., max_length=100),
            description: Optional[str] = FileParam(None, max_length=500),
            file: UploadedFile = FileParam(...),
            folder: Optional[UUID] = FileParam(None)
        ):
    

    Has anything been missed?

    opened by aprilahijriyan 17
  • Authentication Docs Error

    Authentication Docs Error

    image image

    I am trying to use Django Auth system, but the Docs are not working on POST/PUT requests and also on Django core admin requests.

    Config:

    api = NinjaAPI(csrf=True, auth=[django_auth])
    

    The only way I could do to access and execute a POST on the Swagger documentation is by adding @csrf_exempt decorator from django.views.decorators.csrf

    @router.delete('/v1/auth/logout/', auth=None)
    def auth_logout(request):
        logout(request)
        resp = HttpResponseRedirect('/')
        # trocar o método para GET -> 303
        resp.status_code = 303
        return resp
    
    
    @router.post('/v1/auth/status/')
    @csrf_exempt
    def auth_status(request):
        if request.user.is_authenticated:
            return True
        else:
            return HttpError(401, 'Unauthenticated')
    

    I already tryed commenting django.middleware.csrf.CsrfViewMiddleware, but doest work.

    Is there a way to use django_sessions with documentation working on POST requests and default admin endpoints? if not, just allow us to use django_auth without forcing to enable CSRF token pls.

    opened by luizfelipevbll 13
  • Smarter schema that handles dotted aliases and resolver methods

    Smarter schema that handles dotted aliases and resolver methods

    Fixes #291 (even though it was closed) and fixes #250 and adds in new functionality to allow calculated fields via resolve_ static methods on the response schema class.

    Includes tests and docs.

    opened by SmileyChris 12
  • Looks like you created multiple NinjaAPIs

    Looks like you created multiple NinjaAPIs

    Hi there, I was playing around a bit with the basic tutorial (it worked perfectly in the beginning) and got this error at some point:

      File "/django/django_aia_backend/django_aia_backend/urls.py", line 31, in <module>
        path('api/', include(api.urls)),
      File "/djangovenv/lib/python3.9/site-packages/ninja/main.py", line 314, in urls
        self._validate()
      File "/djangovenv/lib/python3.9/site-packages/ninja/main.py", line 398, in _validate
        raise ConfigError("\n".join(msg))
    ninja.errors.ConfigError: Looks like you created multiple NinjaAPIs
    To let ninja distinguish them you need to set either unique version or url_namespace
     - NinjaAPI(..., version='2.0.0')
     - NinjaAPI(..., urls_namespace='otherapi')
    Already registered: ['api-1.0.0']
    

    not sure what is the problem here. I only have one instantiation of NinjaAPI. I tried giving it a specific version name but that does not change anything.

    To be fair, I played around a bit before, among other things creating a django app called 'api' for using standard DRF. I deleted this and every reference to it, but even after starting a brand new django project, the error persists. Does the api instantiation get persisted somewhere in venv? I cannot explain otherwise why this happens.

    opened by Raketuv 12
  • ModelSchema typing

    ModelSchema typing

    Nice project. Good to see the ideas from FastAPI get integrated with Django.

    The problem, when using ModelSchema, an IDE like pycharm does not autocomplete the generated schema.

    class CustomerIn(ModelSchema):
        extra_field: str
    
        class Config:
            model = Customer
            model_fields = ['name', 'date']
    

    Then

    customer: CustomerIn
    customer.name  # unknown field for the IDE
    customer.extra_field  # ok
    

    Possible workarounds?

    opened by asaff1 11
  • __modify_schema__() missing 1 required positional argument: 'field'

    __modify_schema__() missing 1 required positional argument: 'field'

    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/views.py", line 35, in openapi_json schema = api.get_openapi_schema() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/main.py", line 419, in get_openapi_schema return get_schema(api=self, path_prefix=path_prefix) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 40, in get_schema openapi = OpenAPISchema(api, path_prefix) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 62, in init ("paths", self.get_paths()), File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 77, in get_paths path_methods = self.methods(path_view.operations) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 86, in methods operation_details = self.operation_details(op) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 114, in operation_details body = self.request_body(operation) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 228, in request_body model, remove_level=model._param_source == "body" File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 186, in _create_schema_from_model cast(Type[BaseModel], model), ref_prefix=REF_PREFIX, by_alias=by_alias File "pydantic/schema.py", line 167, in pydantic.schema.model_schema File "pydantic/schema.py", line 548, in pydantic.schema.model_process_schema File "pydantic/schema.py", line 589, in pydantic.schema.model_type_schema File "pydantic/schema.py", line 236, in pydantic.schema.field_schema File "pydantic/schema.py", line 303, in pydantic.schema.get_field_schema_validations TypeError: modify_schema() missing 1 required positional argument: 'field' [28/Oct/2022 10:11:46] "GET /api/openapi.json HTTP/1.1" 500 254519 [28/Oct/2022 10:11:46] "GET /api/docs HTTP/1.1" 200 788 Internal Server Error: /api/openapi.json Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/views.py", line 35, in openapi_json schema = api.get_openapi_schema() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/main.py", line 419, in get_openapi_schema return get_schema(api=self, path_prefix=path_prefix) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 40, in get_schema openapi = OpenAPISchema(api, path_prefix) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 62, in init ("paths", self.get_paths()), File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 77, in get_paths path_methods = self.methods(path_view.operations) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 86, in methods operation_details = self.operation_details(op) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 114, in operation_details body = self.request_body(operation) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 228, in request_body model, remove_level=model._param_source == "body" File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 186, in _create_schema_from_model cast(Type[BaseModel], model), ref_prefix=REF_PREFIX, by_alias=by_alias File "pydantic/schema.py", line 167, in pydantic.schema.model_schema File "pydantic/schema.py", line 548, in pydantic.schema.model_process_schema File "pydantic/schema.py", line 589, in pydantic.schema.model_type_schema File "pydantic/schema.py", line 236, in pydantic.schema.field_schema File "pydantic/schema.py", line 303, in pydantic.schema.get_field_schema_validations TypeError: modify_schema() missing 1 required positional argument: 'field' [28/Oct/2022 10:11:47] "GET /api/openapi.json HTTP/1.1" 500 254519 [28/Oct/2022 10:24:17] "GET /api/docs HTTP/1.1" 200 788 Internal Server Error: /api/openapi.json Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/views.py", line 35, in openapi_json schema = api.get_openapi_schema() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/main.py", line 419, in get_openapi_schema return get_schema(api=self, path_prefix=path_prefix) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 40, in get_schema openapi = OpenAPISchema(api, path_prefix) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 62, in init ("paths", self.get_paths()), File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 77, in get_paths path_methods = self.methods(path_view.operations) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 86, in methods operation_details = self.operation_details(op) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 114, in operation_details body = self.request_body(operation) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 228, in request_body model, remove_level=model._param_source == "body" File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ninja/openapi/schema.py", line 186, in _create_schema_from_model cast(Type[BaseModel], model), ref_prefix=REF_PREFIX, by_alias=by_alias File "pydantic/schema.py", line 167, in pydantic.schema.model_schema File "pydantic/schema.py", line 548, in pydantic.schema.model_process_schema File "pydantic/schema.py", line 589, in pydantic.schema.model_type_schema File "pydantic/schema.py", line 236, in pydantic.schema.field_schema File "pydantic/schema.py", line 303, in pydantic.schema.get_field_schema_validations TypeError: modify_schema() missing 1 required positional argument: 'field' [28/Oct/2022 10:24:17] "GET /api/openapi.json HTTP/1.1" 500 254519

    opened by SaluteGF 10
  • Please make the response model optional!

    Please make the response model optional!

    I always get this on openapi.

    ninja.errors.ConfigError: Schema for status 400 is not set in response dict_keys([200])
    

    when I don't add a specific response model, it shouldn't be validated!

    opened by aprilahijriyan 10
  • foreign-key value failed to be valid integer in NinjaResponseSchema

    foreign-key value failed to be valid integer in NinjaResponseSchema

    ValidationError at /api/order/orders
    6 validation errors for NinjaResponseSchema
    response -> 0 -> customer_id
      value is not a valid integer (type=type_error.integer)
    response -> 0 -> vendor_id
      value is not a valid integer (type=type_error.integer)
    response -> 0 -> vender_product_id
      value is not a valid integer (type=type_error.integer)
    response -> 1 -> customer_id
      value is not a valid integer (type=type_error.integer)
    response -> 1 -> vendor_id
      value is not a valid integer (type=type_error.integer)
    response -> 1 -> vender_product_id
      value is not a valid integer (type=type_error.integer)
    

    my schema is like this:

    class OrderSchema(Schema):
        customer_id: int
        vendor_id: int
        vender_product_id: int
        total_product: int
        total_price: int
        created_on: datetime
        updated_on: datetime
    
    opened by ismohamedi 10
  • ATOMIC_REQUESTS and async views

    ATOMIC_REQUESTS and async views

    First of all, thank you very much for your work on this project. I sincerely hope that you and your family are doing well and I sincerely pray for the resolution of the conflict in Ukraine.

    Describe the bug I'm getting a RuntimeError on my django ninja async views when ATOMIC_REQUESTS is true

    Versions

    • Python version: 3.10
    • Django version: 4.0.3
    • Django-Ninja version: 0.17.0
    # settings.py
    DATABASES["default"]["ATOMIC_REQUESTS"] = True
    
    # api.py
    
    
    @transaction.non_atomic_requests
    @router.post("/flight-hotel-search", response=FlightHotelSearchResult)
    async def flight_hotel_search(request:HttpRequest, criteria: FlightHotelSearchCriteria):
      # there is zero database call done by me in this view
      ...
    
    
    
    # Error
    # RuntimeError: You cannot use ATOMIC_REQUESTS with async views.
    
    opened by Tobi-De 9
  • Why flint instead of poetry? How to contribute?

    Why flint instead of poetry? How to contribute?

    Hi! I want to contribute, but i found that project depends on flint and it seems very unfriendly to me.

    It gave 2 questions to me:

    • Could we add some docs for contributors?
    • Could we move to poetry?
    opened by al-stefanitsky-mozdor 9
  • Returning redirect responses in endpoints

    Returning redirect responses in endpoints

    I recently started using Django Ninja, and encountered a scenario where I need to return a redirect response to another endpoint (though it would be cool if I could redirect to any URL). I couldn't find a way to do this, and was unable to use something like redirect()/HttpResponseRedirect (the error I received was Pydantic-related, but I assume that even if validation was disabled, this still wouldn't have worked).

    Is there a way to do this in Django Ninja?

    opened by itaisteinherz 9
  • Is it possible to combine both DRF and Django Ninja API?

    Is it possible to combine both DRF and Django Ninja API?

    I have currently a Django API project built with DRF. I would like to use async for some endpoints to optimize long API calls. Would it be possible and interesting to migrate some endpoints to Django Ninja async ? While keeping the rest with DRF. So I would change my server from WSGI to ASGI. Maybe my understanding of async is not right and the combination of both is bad, I don't know.

    opened by gschurck 1
  • Custom exception handler with TestClient cannot access request data

    Custom exception handler with TestClient cannot access request data

    I have this custom exception handler for PermissionDenied errors:

    @api.exception_handler(PermissionDenied)
    def permission_error(request, exc):
        if 'team_id' in request.resolver_match.captured_kwargs.keys():
            message = "You do not have access to this team."
        else:
            message = "Forbidden."
    
        return api.create_response(
            request,
            {"detail": message},
            status=403,
        )
    

    I'd like to customize the error messages based on information in the request. But using the TestClient, the request is a Mock instance, so I get an TypeError: argument of type 'Mock' is not iterable when trying to access the request's captured kwargs. Is there a way around this?

    opened by LaundroMat 1
  • Adding examples to docs without creating multiple classes

    Adding examples to docs without creating multiple classes

    Let's say I have a ninja.Schema as such:

    class MySchema(ninja.Schema):
       var1: bool
       var2: str = ''
    

    If I have an end-point that returns this schema, I get nice docs. Which I can customize based on error response:

    @router.post('/test', response={200: MyResponse, 400: MyResponse})
    def test(request):
       # some logic here to determine 200 vs 400
       return 200, MyResponse(var1=True)
    

    I am trying to customize the docs to include example values that make sense. Things you would see under 200 vs. 400

    I know I can probably create a class for 200's and a class for 400's, change some default values. But was wondering if there was anyway to directly change the "example-values" that show up in the automated docs? I'd prefer to keep one schema class, and then just customize the "example-value" field in the docs Thanks!

    For example in FastAPI, the responses argument in the .post() method allow for such customization

    responses={
            200: {
                "model": MySchema,
                "description": "customized description here",
                "content": {
                    "application/json": {
                        "example": {
                            'custom key': 'custom value'
                        }
                    }
                }
            },
    }
    

    I'm not sure if I'm a fan of the verbose FastAPI customization, a class would probably make more sense. I was wondering if maybe an object of the Schema could also be passed?

    Something like:

    response={
            200: MySchema(var1=True, var2='200 message'), 201: MySchema(var1=True, var2='201 message'), 
            400: MySchema(var1=False, var2='400 message')
        }
    

    then allowing return values of 200/201/400 with the same schema , just varying instantiations of the schema class

    opened by cca32 1
  • Allow reversing URLs with multiple operations.

    Allow reversing URLs with multiple operations.

    A pretty glaring shortcoming is that it is impossible to reverse URLs that have been registered with same path, but different operations.

    Using the same path for different operations is a pretty common pattern. It is even used throughout Ninja's documentation.

    @router.get("/{identifier}")
    def detail(request, identifier: str):
        return "ok"
    
    @router.put("/{identifier}")
    def update(request, identifier: str, data: Policy):
        return "ok"
    

    The above is perfectly valid, but reversing update using django.urls.reverse() will result in a NoReverseMatch error.

    This commit is an attempt at solving the issue. N.B. I am not familiar with the internals of Ninja. This is just an experiment.

    opened by strange 0
  • 'api-1.0.0' is not a registered namespace

    'api-1.0.0' is not a registered namespace

    I had a new distribution on my project:

    Api-django ----api ----apps --------persons <-- here is my module ----static

    the api function fine but the docs had this message (''api-1.0.0' is not a registered namespace''), and not work

    opened by greathector7 3
Releases(v0.20.0)
  • v0.20.0(Dec 17, 2022)

    What's Changed

    • Speedup code reload by @hiaselhans in https://github.com/vitalik/django-ninja/pull/624
    • Added a support for openapi ServerObject by @Vaiders in https://github.com/vitalik/django-ninja/pull/574
    • Fix url_namespace -> urls_namespace msg by @SmileyChris in https://github.com/vitalik/django-ninja/pull/519
    • add --sorted flag to export_openapi_schema by @hiaselhans in https://github.com/vitalik/django-ninja/pull/571
    • Set correct media type in docs for custom renderer by @Svenito in https://github.com/vitalik/django-ninja/pull/598
    • Update swagger UI to 4.14.0 by @kabell in https://github.com/vitalik/django-ninja/pull/553

    Documentation

    • Shuffle doc files around by @vpoulailleau in https://github.com/vitalik/django-ninja/pull/543
    • Fix README link to "async support" by @denizdogan in https://github.com/vitalik/django-ninja/pull/545
    • Add repository url in pyproject.toml by @baseplate-admin in https://github.com/vitalik/django-ninja/pull/563
    • Set up doc search by @tssujt in https://github.com/vitalik/django-ninja/pull/572

    Misc

    • remove python 3.6 by @hiaselhans in https://github.com/vitalik/django-ninja/pull/625
    • Bump actions/checkout from 2 to 3 by @dependabot in https://github.com/vitalik/django-ninja/pull/411
    • Bump actions/setup-python from 2 to 4 by @dependabot in https://github.com/vitalik/django-ninja/pull/493
    • Fix failing flit build by @baseplate-admin in https://github.com/vitalik/django-ninja/pull/564

    New Contributors

    • @vpoulailleau made their first contribution in https://github.com/vitalik/django-ninja/pull/543
    • @denizdogan made their first contribution in https://github.com/vitalik/django-ninja/pull/545
    • @baseplate-admin made their first contribution in https://github.com/vitalik/django-ninja/pull/563
    • @hiaselhans made their first contribution in https://github.com/vitalik/django-ninja/pull/571
    • @Svenito made their first contribution in https://github.com/vitalik/django-ninja/pull/598
    • @Vaiders made their first contribution in https://github.com/vitalik/django-ninja/pull/574
    • @kabell made their first contribution in https://github.com/vitalik/django-ninja/pull/553

    Full Changelog: https://github.com/vitalik/django-ninja/compare/v0.19.1...v0.20.0

    Source code(tar.gz)
    Source code(zip)
  • v0.19.1(Jul 20, 2022)

    What's Changed

    • Declare the AuthenticationError exception class in all by @duducp in https://github.com/vitalik/django-ninja/pull/489
    • Small fix for many2many payloads to allow passing primary keys for model fields

    Documentation

    • Docs restructure by @SmileyChris in https://github.com/vitalik/django-ninja/pull/334
    • Add documentation on the .from_orm method by @cltrudeau in https://github.com/vitalik/django-ninja/pull/503
    • Added mutiple items example by @ihelmer07 in https://github.com/vitalik/django-ninja/pull/509

    New Contributors

    • @cltrudeau made their first contribution in https://github.com/vitalik/django-ninja/pull/503
    • @ihelmer07 made their first contribution in https://github.com/vitalik/django-ninja/pull/509

    Full Changelog: https://github.com/vitalik/django-ninja/compare/v.0.19.0...v0.19.1

    Source code(tar.gz)
    Source code(zip)
  • v.0.19.0(Jun 29, 2022)

    What's Changed

    • docs decorator by @vitalik in https://github.com/vitalik/django-ninja/pull/488
    • Allow arbitrary Pagination Output ( alternative #464 @rafonseca ) by @vitalik in https://github.com/vitalik/django-ninja/pull/483
    • Update Redoc related documents by @tssujt in https://github.com/vitalik/django-ninja/pull/462
    • Improves authentication validation to throw an exception by @duducp in https://github.com/vitalik/django-ninja/pull/454
    • Add TestClient note to multiple APIs warning by @srcreigh in https://github.com/vitalik/django-ninja/pull/416
    • Implement implicit reverse url name generation by @SmileyChris in https://github.com/vitalik/django-ninja/pull/361
      • Also pass the router to get_operation_url_name by @SmileyChris in https://github.com/vitalik/django-ninja/pull/486
    • [feat] add superuser session authentication only by @areski in https://github.com/vitalik/django-ninja/pull/351

    New Contributors

    • @tssujt made their first contribution in https://github.com/vitalik/django-ninja/pull/462
    • @duducp made their first contribution in https://github.com/vitalik/django-ninja/pull/454
    • @srcreigh made their first contribution in https://github.com/vitalik/django-ninja/pull/416
    • @areski made their first contribution in https://github.com/vitalik/django-ninja/pull/351

    Full Changelog: https://github.com/vitalik/django-ninja/compare/v.0.18.0...v.0.19.0

    Source code(tar.gz)
    Source code(zip)
  • v.0.18.0(Jun 3, 2022)

    Hello

    Please welcome the new Django Ninja version it has lot of fixes and improvements

    Most notable a HttpResponse typed argument by @SmileyChris

    Now you can manage response behaviour (cookies, headers, streaming) flixible:

    @api.post("/boop")
    def boop(request, response: HttpResponse): # !
        response.set_cookie("beep", "boop") # !
        return True
    

    All changes

    • Provide a temporal HttpResponse typed argument to views by @SmileyChris in https://github.com/vitalik/django-ninja/pull/336
    • UploadedFile inherit from Django's UploadedFile by @OtherBarry in https://github.com/vitalik/django-ninja/pull/400
    • Allow path parameters to be specified at router level by @kaschnit in https://github.com/vitalik/django-ninja/pull/369
    • Added support for postgress specific fields to Model Schema #353
    • Fixed openapi/pydantic versions compatibility #418
    • pre-commit config by @SmileyChris in https://github.com/vitalik/django-ninja/pull/364
    • Access to test response attributes by @stephane in https://github.com/vitalik/django-ninja/pull/402
    • Small optimization and typing improvements by @SmileyChris in https://github.com/vitalik/django-ninja/pull/367
    • Minor typo in tutorial by @stephane in https://github.com/vitalik/django-ninja/pull/387
    • Specify mypy in CONTRIBUTING.md by @OtherBarry in https://github.com/vitalik/django-ninja/pull/401
    • ConfigError: ModelSchema classes requires a 'Config' subclass by @sebastian-philipp in https://github.com/vitalik/django-ninja/pull/382
    • Fix a typing issue by @HoJin9622 in https://github.com/vitalik/django-ninja/pull/404
    • Fix a few typos by @dy3l in https://github.com/vitalik/django-ninja/pull/426
    • Add Redoc support by @kxxoling in https://github.com/vitalik/django-ninja/pull/427
    • Fix typo in docs by @sho918 in https://github.com/vitalik/django-ninja/pull/432
    • Handle class instances in signature.details.is_collection_type by @flaeppe in https://github.com/vitalik/django-ninja/pull/434
    • Upgrade versions of pre-commit hooks by @flaeppe in https://github.com/vitalik/django-ninja/pull/435

    New Contributors

    • @kaschnit made their first contribution in https://github.com/vitalik/django-ninja/pull/369
    • @stephane made their first contribution in https://github.com/vitalik/django-ninja/pull/387
    • @OtherBarry made their first contribution in https://github.com/vitalik/django-ninja/pull/400
    • @sebastian-philipp made their first contribution in https://github.com/vitalik/django-ninja/pull/382
    • @HoJin9622 made their first contribution in https://github.com/vitalik/django-ninja/pull/404
    • @dy3l made their first contribution in https://github.com/vitalik/django-ninja/pull/426
    • @kxxoling made their first contribution in https://github.com/vitalik/django-ninja/pull/427
    • @sho918 made their first contribution in https://github.com/vitalik/django-ninja/pull/432
    • @flaeppe made their first contribution in https://github.com/vitalik/django-ninja/pull/434

    Full Changelog: https://github.com/vitalik/django-ninja/compare/v0.17.0...v0.18.0

    Source code(tar.gz)
    Source code(zip)
  • v0.17.0(Feb 3, 2022)

    This release brings few long awaited features:

    Smarter schema

    Now you can access orm instance attributes inside schema with resolvers:

    class TaskSchema(Schema):
        title: str
        is_completed: bool
        owner: Optional[str]
        lower_title: str
    
        @staticmethod
        def resolve_owner(obj):  # <------- !!!!!!
            if not obj.owner:
                return
            return f"{obj.owner.first_name} {obj.owner.last_name}"
    
        def resolve_lower_title(self, obj):   # <-------- !!!!!!
            return self.title.lower()
    

    Field aliases now support django template variables dotted syntax:

    class TaskSchema(Schema):
        ...
        last_comment: str = Field(..., alias="comment_set.0.text")
    

    Thanks to @SmileyChris

    Pagination output

    Now default paginated output returns a dict with items and count

    You can now override both input and output schemas for custom pagination:

    class CustomPagination(PaginationBase):
    
        class Input(Schema):
            page: int
            
        class Output(Schema):
            items: List[Any]
            total_pages: int
            current_page: int
        
        def paginate_queryset(self, queryset, pagination: Input, **params):
            return {
                'items': ...,
                'total_pages': ...,
                'current_page': ...,
            }
    

    All updates:

    • Improved pagination by @vitalik
    • Smarter schema that handles dotted aliases and resolver methods by @SmileyChris #317
    • Add support for union type in payload by @AkeemMcLennon #301
    • Export OpenAPI schema management cmd by @stefanitsky #288
    • First key derivation optimization by @mom1 #344
    • **kwargs not required anymore for pagination by @mom1 #285

    New Contributors

    • @AkeemMcLennon
    • @stefanitsky
    • @mom1

    Full Changelog: https://github.com/vitalik/django-ninja/compare/v0.16.2...v0.17.0

    Source code(tar.gz)
    Source code(zip)
  • v0.16.2(Jan 20, 2022)

    • Pydantic 1.9.0 support #310 by @antonrh
    • Fix params descriptions visualization in swagger ui #331 by @ldbenitez
    • Improve TestClient json argument-serialization #315 by @johnbergvall
    • Add python 3.10 to test matrix #273 by @jairhenrique
    • Automate github actions update. #274 by @jairhenrique

    Many documentaion fixes and improvements by:

    • @daviddavis
    • @shamaevnn
    • @SmileyChris
    • @antonrh
    • @s3lcuk
    • @idahogray
    • @TaeHyoungKwon
    • @dekoza
    Source code(tar.gz)
    Source code(zip)
  • v0.16.1(Oct 12, 2021)

    • Resolve #229 & #240 reporting dev errors under django dev-server (#242 by @stephenrauch)
    • Allow NOT_SET to survive copy.deepcopy() (#241 by @stephenrauch)
    Source code(tar.gz)
    Source code(zip)
  • v0.16.0(Oct 6, 2021)

    OpenAPI schemas names

    Generating OpenAPI automatically created schema names changed for duplicated names (see #230) Now instead of silence (or exceptions on other cases) django-ninja will just add sequential number suffix to the schema name in OpenAPI spec. For example if you already have schema called "User" and in some other module you create another "User" schema - the second will have name "User2" in openapi json.

    Other

    • Dot in query regression #238 (#239 by @stephenrauch)
    • Fix openapi schema title and description propagation for query, cookie, header, etc #123 (#233 from @stephenrauch)
    • Fix form schema single param #236 (#237 from @stephenrauch)
    • Improve #181, query with list type (#234 by @stephenrauch)
    • Path signature check (#232 by @stephenrauch)
    • Document how to handle empty form fields (#228 by @stephenrauch)
    • Misc fixes (#231 by @ehdgua01)
    Source code(tar.gz)
    Source code(zip)
  • v0.15.0(Sep 18, 2021)

    Major changes

    • Introduced ModelSchema - declarative way to create schemas from django models
    • Allow arbitrary mix of params Body, Form & File w/ multipart. (#226 by @stephenrauch) (also fixes #134, #162, #201)
    • Path params now support Django path converters (#187 by @stephenrauch)

    Other changes

    • Fixed #208 - Missing schema in requestBody (#209 by @stephenrauch)
    • UploadedFile usability #120
    • Types for "urls" property #155
    • Optimize tests (#217 by @mawassk)
    • Better error message for duplicate orm schema names #214 (#215 @stephenrauch)
    • Test coverage for branches (#211 @stephenrauch)
    • Formatting & styling for test files (#218 by @stephenrauch)
    • Documentation improvements (#207 by @eadwinCode, #205 #206 by @johnthagen )
    Source code(tar.gz)
    Source code(zip)
  • v0.14.0(Aug 14, 2021)

    Hello Everyone,

    This is a very nice release, which includes some new functionality and fixes And more important there are lot of people contributed to this update Thank you

    • Added experimental Pagination support - allows you easely paginate your querysets and customize pages (note - this feature currently in beta and may change a bit in future udpates)
    • Added support for streaming responses (#149 by @ErwinJunge )
    • Mixing simple arguments and models arguments in GET parameters (#178 by @stephenrauch )
    • Handle custom exceptions in authentication (#174 by @dozer133 )
    • Added build_absolute_uri on test client (#168 by @jairhenrique )
    • Typing improvements (#167, #170 by @davidszotten )
    • Fix assertion message (#175 by @igoose1 )
    • Resolve #148, missing wraps(), with a better error message. (#184 by @stephenrauch)
    • Improved documentation on forward refs ( #161 by @stephenrauch )
    • Fixed add_router() to router already attached to API ( #188 by @stephenrauch )
    • Bumped Swagger UI to 3.51.2 ( #192 by @igoose1 )
    Source code(tar.gz)
    Source code(zip)
  • v0.13.2(Jun 5, 2021)

  • v0.13.1(Jun 3, 2021)

  • v0.13.0(May 18, 2021)

    • Fixed create_schema ValueError on pydantic 1.8.2 (#135)
    • Allow collection fields to be identified when an alias is used #133 (by @kierandarcy )
    • New argument custom_fields in create_schema to override or add fields
    • Fixed create_schema Json field (#127)
    • Include ninja TestClient into distributed package
    Source code(tar.gz)
    Source code(zip)
  • v0.12.3(Apr 28, 2021)

  • v0.12.2(Apr 6, 2021)

  • v0.12.1(Mar 26, 2021)

  • v0.12.0(Mar 26, 2021)

  • v0.11.0(Mar 3, 2021)

  • v0.10.2(Feb 2, 2021)

  • 0.10.1(Jan 15, 2021)

  • v0.10.0(Jan 13, 2021)

  • v0.9.7(Dec 25, 2020)

  • v0.9.6(Dec 21, 2020)

  • v0.9.4(Dec 14, 2020)

  • v0.9.3(Dec 14, 2020)

Embrace the APIs of the future. Hug aims to make developing APIs as simple as possible, but no simpler.

Read Latest Documentation - Browse GitHub Code Repository hug aims to make developing Python driven APIs as simple as possible, but no simpler. As a r

Hug API Framework 6.7k Dec 27, 2022
Sanic-RESTPlus is an extension for Sanic that adds support for quickly building REST APIs.

Sanic RestPlus Sanic-RESTPlus is an extension for Sanic that adds support for quickly building REST APIs. Sanic-RESTPlus encourages best practices wit

Ashley Sommer 106 Oct 14, 2022
Web APIs for Django. 🎸

Django REST framework Awesome web-browsable Web APIs. Full documentation for the project is available at https://www.django-rest-framework.org/. Fundi

Encode 24.7k Jan 4, 2023
Browsable web APIs for Flask.

Flask API Browsable web APIs for Flask. Status: This project is in maintenance mode. The original author (Tom Christie) has shifted his focus to API S

Flask API 1.3k Dec 27, 2022
Creating delicious APIs for Django apps since 2010.

django-tastypie Creating delicious APIs for Django apps since 2010. Currently in beta but being used actively in production on several sites. Requirem

null 3.8k Dec 30, 2022
Scaffold django rest apis like a champion 🚀

scaffold django rest apis like a champion ??

Abdenasser Elidrissi 133 Jan 5, 2023
A small repository of projects built in my course, REST APIs with Flask and Python.

A small repository of projects built in my course, REST APIs with Flask and Python.

Teclado 1k Jan 5, 2023
A JSON Web Token authentication plugin for the Django REST Framework.

Simple JWT Abstract Simple JWT is a JSON Web Token authentication plugin for the Django REST Framework. For full documentation, visit django-rest-fram

Jazzband 3.3k Jan 4, 2023
RESTler is the first stateful REST API fuzzing tool for automatically testing cloud services through their REST APIs and finding security and reliability bugs in these services.

RESTler is the first stateful REST API fuzzing tool for automatically testing cloud services through their REST APIs and finding security and reliability bugs in these services.

Microsoft 1.8k Jan 4, 2023
Country-specific Django helpers, to use in Django Rest Framework

django-rest-localflavor Country-specific serializers fields, to Django Rest Framework Documentation (soon) The full documentation is at https://django

Gilson Filho 19 Aug 30, 2022
Async Python 3.6+ web server/framework | Build fast. Run fast.

Sanic | Build fast. Run fast. Build Docs Package Support Stats Sanic is a Python 3.6+ web server and web framework that's written to go fast. It allow

Sanic Community Organization 16.7k Dec 28, 2022
Generate Views, Serializers, and Urls for your Django Rest Framework application

DRF Generators Writing APIs can be boring and repetitive work. Don't write another CRUDdy view in Django Rest Framework. With DRF Generators, one simp

Tobin Brown 332 Dec 17, 2022
BloodDonors: Built using Django REST Framework for the API backend and React for the frontend

BloodDonors By Daniel Yuan, Alex Tian, Aaron Pan, Jennifer Yuan As the pandemic raged, one of the side effects was an urgent shortage of blood donatio

Daniel Yuan 1 Oct 24, 2021
Authentication for Django Rest Framework

Dj-Rest-Auth Drop-in API endpoints for handling authentication securely in Django Rest Framework. Works especially well with SPAs (e.g React, Vue, Ang

Michael 1.1k Dec 28, 2022
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.

drf-yasg - Yet another Swagger generator Generate real Swagger/OpenAPI 2.0 specifications from a Django Rest Framework API. Compatible with Django Res

Cristi Vîjdea 3k Jan 6, 2023
Introduction to Django Rest Framework

Introduction to Django Rest Framework This is the repository of the video series Introduction to Django Rest Framework published on YouTube. It is a s

Simple is Better Than Complex 20 Jul 14, 2022
JSON:API support for Django REST framework

JSON:API and Django REST framework Overview JSON:API support for Django REST framework Documentation: https://django-rest-framework-json-api.readthedo

null 1k Dec 27, 2022
DRF-extensions is a collection of custom extensions for Django REST Framework

Django REST Framework extensions DRF-extensions is a collection of custom extensions for Django REST Framework Full documentation for project is avail

Gennady Chibisov 1.3k Dec 28, 2022