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)

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 02, 2023
Djask is a web framework for python which stands on the top of Flask and will be as powerful as Django.

Djask is a web framework for python which stands on the top of Flask and will be as powerful as Django.

Andy Zhou 27 Sep 08, 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 03, 2023
Trame let you weave various components and technologies into a Web Application solely written in Python.

Trame Trame aims to be a framework for building interactive applications using a web front-end in plain Python. Such applications can be used locally

Kitware, Inc. 85 Dec 29, 2022
Cses2humio - CrowdStrike Falcon Event Stream to Humio

CrowdStrike Falcon Event Stream to Humio This project intend to provide a simple

Trifork.Security 6 Aug 02, 2022
Phoenix LiveView but for Django

Reactor, a LiveView library for Django Reactor enables you to do something similar to Phoenix framework LiveView using Django Channels. What's in the

Eddy Ernesto del Valle Pino 526 Jan 02, 2023
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
APIFlask is a lightweight Python web API framework based on Flask and marshmallow-code projects

APIFlask APIFlask is a lightweight Python web API framework based on Flask and marshmallow-code projects. It's easy to use, highly customizable, ORM/O

Grey Li 705 Jan 04, 2023
Flask like web framework for AWS Lambda

lambdarest Python routing mini-framework for AWS Lambda with optional JSON-schema validation. ⚠️ A user study is currently happening here, and your op

sloev / Johannes Valbjørn 91 Nov 10, 2022
Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.

Japronto! There is no new project development happening at the moment, but it's not abandoned either. Pull requests and new maintainers are welcome. I

Paweł Piotr Przeradowski 8.6k Dec 29, 2022
An easy-to-use high-performance asynchronous web framework.

中文 | English 一个易用的高性能异步 web 框架。 Index.py 文档 Index.py 实现了 ASGI3 接口,并使用 Radix Tree 进行路由查找。是最快的 Python web 框架之一。一切特性都服务于快速开发高性能的 Web 服务。 大量正确的类型注释 灵活且高效的

Index.py 264 Dec 31, 2022
Python implementation of the Javascript Object Signing and Encryption (JOSE) framework

Python implementation of the Javascript Object Signing and Encryption (JOSE) framework

Demonware 94 Nov 20, 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
A library that makes consuming a RESTful API easier and more convenient

Slumber is a Python library that provides a convenient yet powerful object-oriented interface to ReSTful APIs. It acts as a wrapper around the excellent requests library and abstracts away the handli

Sam Giles 597 Dec 13, 2022
A simple Tornado based framework designed to accelerate web service development

Toto Toto is a small framework intended to accelerate web service development. It is built on top of Tornado and can currently use MySQL, MongoDB, Pos

Jeremy Olmsted-Thompson 61 Apr 06, 2022
Bromelia-hss implements an HSS by using the Python micro framework Bromélia.

Bromélia HSS bromelia-hss is the second official implementation of a Diameter-based protocol application by using the Python micro framework Bromélia.

henriquemr 7 Nov 02, 2022
Daniel Vaz Gaspar 4k Jan 08, 2023
TinyAPI - 🔹 A fast & easy and lightweight WSGI Framework for Python

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

xArty 3 Apr 08, 2022
An effective, simple, and async security library for the Sanic framework.

Sanic Security An effective, simple, and async security library for the Sanic framework. Table of Contents About the Project Getting Started Prerequis

Sunset Dev 72 Nov 30, 2022
Chisel is a light-weight Python WSGI application framework built for creating well-documented, schema-validated JSON web APIs

chisel Chisel is a light-weight Python WSGI application framework built for creating well-documented, schema-validated JSON web APIs. Here are its fea

Craig Hobbs 2 Dec 02, 2021