I am working on a Django project and there's requirement to build the APIs without using the Django rest-framework library.
I'm having a hard time figuring out a work around as most available libraries are already tied to the Django rest-framework pip library.
Can someone point me to an example, library or resource for self documented APIs using swagger docs that
supports at least Python 3.7
Django REST framework (DRF) is a powerful and flexible toolkit for building Web APIs. Its main benefit is that it makes serialization much easier. Django REST framework is based on Django's class-based views, so it's an excellent option if you're familiar with Django.
For a quick start, use shortcut method get_swagger_view which will generate Swagger UI documentation for your API. This method have two optional parameters title (of your Swagger documentation) and url (to your Swagger documentation).
Django is the web development framework in python whereas the Django Rest Framework is the library used in Django to build Rest APIs. Django Rest Framework is especially designed to make the CRUD operations easier to design in Django. Django Rest Framework makes it easy to use your Django Server as an REST API.
You can generate API Docs using APISpec (https://pypi.org/project/apispec/)
APISpec supports OpenAPI and marshmallow and can be implemented in Plain python and is not tied to Django Framework
You can specify the content of the doc using Doc String in the following way,
@app.route("/random")
def random_pet():
"""A cute furry animal endpoint.
---
get:
description: Get a random pet
security:
- ApiKeyAuth: []
responses:
200:
content:
application/json:
schema: PetSchema
"""
pet = get_random_pet()
return PetSchema().dump(pet)
Docs: https://apispec.readthedocs.io/en/latest/
There are several ways to build api's without using Django REST Framework, some of alternatives include:
FAST API - https://fastapi.tiangolo.com/
Flask - https://flask.palletsprojects.com/en/2.0.x/
Cherrypy - https://docs.cherrypy.dev/en/latest/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With