Package: django-restql
Django RESTQLDjango RESTQLis a python library which allows you to turn your API made withDjango REST Framework(DRF)into a GraphQL like API. WithDjango RESTQLyou will be able toSend a query to your API and get exactly what you need, nothing more and nothing less.Control the data you get, not the server.Get predictable results, since you control what you get from the server.Get nested resources in a single request.Avoid Over-fetching and Under-fetching of data.Write(create & update) nested data of any level in a single request.Isn't it cool?.Want to see how this library is making all that possible?Check out the full documentation athttps://yezyilomo.github.io/django-restqlOr try a live demo onDjango RESTQL PlaygroundRequirementsPython >= 3.6Django >= 1.11Django REST Framework >= 3.5Installingpipinstalldjango-restqlGetting StartedUsingDjango RESTQLto query data is very simple, you just have to inherit theDynamicFieldsMixinclass when defining a serializer that's all.fromrest_frameworkimportserializersfromdjango.contrib.auth.modelsimportUserfromdjango_restql.mixinsimportDynamicFieldsMixinclassUserSerializer(DynamicFieldsMixin,serializer.ModelSerializer):classMeta:model=Userfields=['id','username','email']Django RESTQLhandle all requests with aqueryparameter, this parameter is the one used to pass all fields to be included/excluded in a response. For example to selectidandusernamefields from User model, send a request with aqueryparameter as shown below.GET /users/?query={id, username}[{"id":1,"username":"yezyilomo"},...]Django RESTQLsupport querying both flat and nested resources, so you can expand or query nested fields at any level as defined on a serializer. In an example below we havelocationas a nested field on User model.fromrest_frameworkimportserializersfromdjango.contrib.auth.modelsimportUserfromdjango_restql.mixinsimportDynamicFieldsMixinfromapp.modelsimportGroupSerializer,LocationSerializerclassLocationSerializer(DynamicFieldsMixin,serializer.ModelSerializer):classMeta:model=Locationfields=['id','country','city','street']classUserSerializer(DynamicFieldsMixin,serializer.ModelSerializer):location=LocationSerializer(many=False,read_only=True)classMeta:model=Userfields=['id','username','email','location']If you want onlycountryandcityfields on alocationfield when retrieving users here is how you can do itGET /users/?query={id, username, location{country, city}}[{"id":1,"username":"yezyilomo","location":{"contry":"Tanzania","city":"Dar es salaam"}},...]You can even rename your fields when querying data, In an example below the fieldlocationis renamed toaddressGET /users/?query={id, username, address: location{country, city}}[{"id":1,"username":"yezyilomo","address":{"contry":"Tanzania","city":"Dar es salaam"}},...]Documentation :pencil:You can do a lot withDjango RESTQLapart from querying data, likeRename fieldsRestrict some fields on nested fieldsDefine self referencing nested fieldsOptimize data fetching on nested fieldsData filtering and pagination by using query argumentsData mutation(Create and update nested data of any level in a single request)Full documentation for this project is available athttps://yezyilomo.github.io/django-restql, you are advised to read it inorder to utilize this library to the fullest.Django RESTQL Play GroundDjango RESTQL Play Groundis a graphical, interactive, in-browser tool which you can use to testDjango RESTQLfeatures like data querying, mutations etc to get the idea of how the library works before installing it. It's more like alive demoforDjango RESTQL, it's available athttps://django-restql-playground.yezyilomo.meRunning Testspython runtests.pyCreditsImplementation of this library is based on the idea behindGraphQL.My intention is to extend the capability ofdrf-dynamic-fieldslibrary to support more functionalities like allowing to query nested fields both flat and iterable at any level and allow writing on nested fields while maintaining simplicity.ContributingWe welcome all contributions. Please read ourCONTRIBUTING.mdfirst. You can submit any ideas aspull requestsor asGitHub issues. If you'd like to improve code, check out theCode Style Guideand have a good time!.