Package: bridgeql
BridgeQLbridgeqlis part of VMware's support for open source development
and community.A library which will add feature to serve your model over rest APIThis will allow users to make ORM query based on any models present in the django appThis will ask user to provide request in defined format and will serve the API response as json dataThis will allow users to make filter, selection, ordering, slicing and count of model objectsAs of today we only support fordjango, will add support forsqlalchemysoon.Licensebridgeqlis release under the BSD-2 license, see theLICENSEfile.SPDX-License-Identifier: BSD-2-ClauseDjango IntegrationInstallationYou can install it directly frompypi.orgusingpipinstallbridgeqlThe bridgeql library can be integrated to the Django app by editing settings
file by includingbridgeqlin thesettings.INSTALLED_APPSvariable.
Another change required is to add a url to your existing project asprojectname/projectname/settings.pyINSTALLED_APPS=[...'bridgeql',...]URLs ConfigurationIn your project you can editurls.py, to include thebridgeqlurls.frombridgeql.djangoimporturlsasbridgeql_urls...urlpatterns=[...path('api/bridgeql/',include(bridgeql_urls)),...]...This way your app will be ready to serve the REST API to expose model query, you can request the API
to perform basic CRUD operations using one of the following URLsCreate:create/db_name/app_name/model_nameRead:read/db_name/app_name/model_name/<?pk>Update:update/db_name/app_name/model_name/pkDelete:delete/db_name/app_name/model_name/pkExample Usage:importrequestsparams={'filter':{'os__name':'os-name-1'},'fields':['ip','name','id'],'exclude':{'name':'machine-name-11'},'order_by':['ip'],'limit':5,'offset':10,# default 0}# db_name could be defaultapi_url='<yoursite.com>/api/bridgeql/read/default/machine/Machine'resp=requests.get(api_url,{'payload':json.dumps(params)})result=resp.json()The above parameters will translate into running the model query forMachinemodel ofmachinedjango app.Machine.objects.using('default').filter(os__name='os-name-1').exclude(name='machine-name-11').values(['ip','name','id']).order_by('ip')[10:15]# offset: offset + limitBridgeQL SettingsSettings available inBridgeQLand their default valuesBRIDGEQL_ALLOWED_APPSDefault:[list of local apps](list)By default, it will try to lookup your local apps for the project, consideringsettings.BASE_DIRorsettings.SITE_ROOT(whichever is found) as your project root directory. If none of this will be available,WARNINGwill be there to setupBRIDGEQL_ALLOWED_APPSas application starts up.Adding values as list of desired apps toBRIDGEQL_ALLOWED_APPSwill allow you expose models only for the selected apps.
This way you can add django backend apps as well as third party apps e.g.django.contrib.authwhich can exposeUsermodel.
You can combine next settingsBRIDGEQL_RESTRICTED_MODELSto restrict few columns of that particular model e.gpassword.BRIDGEQL_ALLOWED_APPS=['machine','django.contrib.auth']BRIDGEQL_RESTRICTED_MODELSDefault:{}(Empty dictionary)Dictionary mappingapp_label.model_namestrings to list/bool(True). The value represents list of fields to be restricted for the model as provided in key. If the value is set toTrue, all the fields of that model will be restricted to lookup.BRIDGEQL_RESTRICTED_MODELS={'auth.User':True,'machine.OperatingSystem':['license_key'],}BRIDGEQL_AUTHENTICATION_DECORATORDefault:{
  'reader': '',
  'writer': ''
}Above setting allows you to use an authentication decorator to authenticate your client's requests.
You can provide a custom authentication decorator,
for reader and writer separately, whichever suits your application usecase, e.g login_required, same_subnet, etc.Default value forBRIDGEQL_AUTHENTICATION_DECORATORwill allow you to access API without authentication.BRIDGEQL_AUTHENTICATION_DECORATOR={'reader':'bridgeql.auth.basic_auth','writer':'bridgeql.auth.basic_auth'}bridgeql.auth.basic_authis available as a basic authentication method where you can pass authorization header asAuthorization: Basic base64(username:password)for each request.Build & Runmake testsource venv/bin/activate && toxpython -m pip install --upgrade buildpython -m buildDocumentationContributingThe bridgeql project team welcomes contributions from the community. Before you start working with bridgeql, please
read ourDeveloper Certificate of Origin. All contributions to this repository must be
signed as described on that page. Your signature certifies that you wrote the patch or have the right to pass it on
as an open-source patch. For more detailed information, refer toCONTRIBUTING_DCO.md.AuthorsCreated and maintained byPiyus KumarPriyank SinghCopyright © 2023, VMware, Inc.  All rights reserved.