Django Ninja - Fast Django REST Framework

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
  • why use field.verbose_name.title() instead of field.verbose_name in orm/fields.py

    why use field.verbose_name.title() instead of field.verbose_name in orm/fields.py

    As the title says.... When we have lazy texts as verbose_names for django model fields, the schema generation will not use these in the correct language. Calling field.verbose_name.title() will evaluate it when the model is loaded and not when openapi.json is generated.

    Changing field.verbose_name.title() to field.verbose_name resolves this issue, but I would like to know if this can cause other unexpected issues.

    opened by adi1 2
  • Add urls_namespace option for Routers

    Add urls_namespace option for Routers

    It would be good to be able to provide the urls_namespace kwarg when creating a router, to easily allow more fine-grained namespacing of urls. (I can see this was considered by SmileyChris in #361 but not included in that PR).

    ie. something like this:

    router = Router(urls_namespace='foo')
    
    @router.get('/')
    def bar(request):
        return 'bar'
    
    api.add_router('/foo/', router)
    

    would result in the endpoint having a url named api-1.0.0:foo:bar.

    Nested routers would need to be considered, but I think it makes sense for the url namespaces to be similarly nested:

    router = Router(urls_namespace='foo')
    nested_router = Router(urls_namespace='baz')
    
    @nested_router.get('/')
    def bar(request):
        return 'bar'
    
    router.add_router('/baz/', nested_router)
    api.add_router('/foo/', router)
    

    -> api-1.0.0:foo:baz:bar

    opened by sumebrius 0
  • 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
  • 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 3
  • 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
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)

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
The no-nonsense, minimalist REST and app backend framework for Python developers, with a focus on reliability, correctness, and performance at scale.

The Falcon Web Framework Falcon is a reliable, high-performance Python web framework for building large-scale app backends and microservices. It encou

Falconry 9k Jan 1, 2023
REST API framework designed for human beings

Eve Eve is an open source Python REST API framework designed for human beings. It allows to effortlessly build and deploy highly customizable, fully f

eve 6.6k Jan 7, 2023
REST API framework designed for human beings

Eve Eve is an open source Python REST API framework designed for human beings. It allows to effortlessly build and deploy highly customizable, fully f

eve 6.3k Feb 17, 2021
Goblet is an easy-to-use framework that enables developers to quickly spin up fully featured REST APIs with python on GCP

GOBLET Goblet is a framework for writing serverless rest apis in python in google cloud. It allows you to quickly create and deploy python apis backed

Austen 78 Dec 27, 2022
Endpoints is a lightweight REST api framework written in python and used in multiple production systems that handle millions of requests daily.

Endpoints Quickest API builder in the West! Endpoints is a lightweight REST api framework written in python and used in multiple production systems th

Jay Marcyes 30 Mar 5, 2022
An alternative serializer implementation for REST framework written in cython built for speed.

drf-turbo An alternative serializer implementation for REST framework written in cython built for speed. Free software: MIT license Documentation: htt

Mng 74 Dec 30, 2022
Fast, asynchronous and elegant Python web framework.

Warning: This project is being completely re-written. If you're curious about the progress, reach me on Slack. Vibora is a fast, asynchronous and eleg

vibora.io 5.7k Jan 8, 2023
FastAPI framework, high performance, easy to learn, fast to code, ready for production

FastAPI framework, high performance, easy to learn, fast to code, ready for production Documentation: https://fastapi.tiangolo.com Source Code: https:

Sebastián Ramírez 53k Jan 2, 2023
bottle.py is a fast and simple micro-framework for python web-applications.

Bottle: Python Web Framework Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module a

Bottle Micro Web Framework 7.8k Dec 31, 2022
Fully featured framework for fast, easy and documented API development with Flask

Flask RestPlus IMPORTANT NOTICE: This project has been forked to Flask-RESTX and will be maintained by by the python-restx organization. Flask-RESTPlu

Axel H. 2.7k Jan 4, 2023
Fully featured framework for fast, easy and documented API development with Flask

Flask RestPlus IMPORTANT NOTICE: This project has been forked to Flask-RESTX and will be maintained by by the python-restx organization. Flask-RESTPlu

Axel H. 2.5k Feb 17, 2021
FPS, fast pluggable server, is a framework designed to compose and run a web-server based on plugins.

FPS, fast pluggable server, is a framework designed to compose and run a web-server based on plugins. It is based on top of fastAPI, uvicorn, typer, and pluggy.

Adrien Delsalle 1 Nov 16, 2021
Fast⚡, simple and light💡weight ASGI micro🔬 web🌏-framework for Python🐍.

NanoASGI Asynchronous Python Web Framework NanoASGI is a fast ⚡ , simple and light ?? weight ASGI micro ?? web ?? -framework for Python ?? . It is dis

Kavindu Santhusa 8 Jun 16, 2022
Appier is an object-oriented Python web framework built for super fast app development.

Joyful Python Web App development Appier is an object-oriented Python web framework built for super fast app development. It's as lightweight as possi

Hive Solutions 122 Dec 22, 2022
A minimal, extensible, fast and productive API framework for Python 3.

molten A minimal, extensible, fast and productive API framework for Python 3. Changelog: https://moltenframework.com/changelog.html Community: https:/

Bogdan Popa 980 Nov 28, 2022
Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source

Bionic is fast. It's powered core python without any extra dependencies. Bionic offers stateful hot reload, allowing you to make changes to your code and see the results instantly without restarting your app or losing its state.

 ⚓ 0 Mar 5, 2022
TinyAPI - 🔹 A fast & easy and lightweight WSGI Framework for Python

TinyAPI - ?? A fast & easy and lightweight WSGI Framework for Python

xArty 3 Apr 8, 2022
A Flask API REST to access words' definition

A Flask API to access words' definitions

Pablo Emídio S.S 9 Jul 22, 2022