Package: khapi
Django KHAPIKhapi is a powerful Django app that simplifies the process of creating APIs for your Django web app. It utilizes a Reverse Hash Table to optimize data retrieval and provides easy-to-use API classes for various operations.FeaturesReverse Hash Table:Efficiently stores and retrieves data from your Django models.Simple API Creation:Create APIs with minimal code using predefined classes.Built-in API Classes:Includes ListAPI, ListByValueAPI, GetByIdAPI, SearchAPI, CreateAPI, UpdateAPI, and ImageSearchAPI.Image Search:Utilize AI-based image search functionality.API Security Settings:Django admin integration for managing API authorization settings.Getting StartedInstallationInstall khapi using pip:pipinstallkhapiIn your Django project’s settings.py, add the following configurations:INSTALLED_APPS=["khapi","khapi.auth_system",# ... other apps ...]#For your User modelAUTH_USER_MODEL="your_app.CustomUser"KHAPI={"CACHE_APPS":["your_apps",],}Now, go to any app file, specifically urls.py, and add the following to initialize khapi:fromkhapi.khapi_startimportkhapi_cache_startkhapi_cache_start()After making these changes, run the following command:pythonmanage.pykhapi*After any use of python manage.py makemigrations, you need to run python manage.py khapi to create a cache dict for your models.ExampleTo create an API endpoint that returns a list of all your model data by field value:# app/views.pyfrom.modelsimportLanguagefromkhapi.viewsimport(ListByValueAPI,)classLanguageListByValueAPI(ListByValueAPI):model=Language# app/urls.pyfromkhapi.khapi_startimportkhapi_cache_startfrom.importviewsfromdjango.urlsimportpathkhapi_cache_start()urlpatterns=[path("language/value/<str:value>/",views.LanguageListByValueAPI.as_api(),name="languagebyvalue-view",),]# project/urls.pyfromdjango.urlsimportinclude,pathurlpatterns=[path('admin/',admin.site.urls),path("your_app/",include("your_app.urls")),]Fastest GET Response EverFastest GET Response EverBuilt-in API ClassesKhAPI comes with several built-in API classes that make it easy to create APIs for your Django models. Below is a brief overview of each class:ListAPIDescription:Returns all data from the model as a list.Usage:fromkhapi.viewsimportListAPIclassYourListAPI(ListAPI):model=YourModelListByValueAPIDescription:Returns data from the model based on a specified field value.Usage:fromkhapi.viewsimportListByValueAPIclassYourListByValueAPI(ListByValueAPI):model=YourModelGetByIdAPIDescription:Returns data from the model based on the specified ID.Usage:fromkhapi.viewsimportGetByIdAPIclassYourGetByIdAPI(GetByIdAPI):model=YourModelSearchAPIDescription:Searches for data in the model based on specified values.Usage:fromkhapi.viewsimportSearchAPIclassYourSearchAPI(SearchAPI):model=YourModelCreateAPIDescription:Creates new entries in the model.Usage:fromkhapi.viewsimportCreateAPIclassYourCreateAPI(CreateAPI):model=YourModelUpdateAPIDescription:Updates existing entries in the model.Usage:fromkhapi.viewsimportUpdateAPIclassYourUpdateAPI(UpdateAPI):model=YourModelImageSearchAPIVisitkhapitoolsfor installation.Description:Utilizes AI-based image search functionality.Usage:fromkhapitools.viewsimportImageSearchAPIclassYourImageSearchAPI(ImageSearchAPI):model=YourModelLicenseThis project is licensed under the MIT License.SupportFor questions or issues, please open an issue or contact us athamza.alkhatib.se@gmail.comAcknowledgmentsThanks to the Django community.