Skip to main content

Query language to bridge the gap between REST API and ORM capability

Project description

BridgeQL

bridgeql is part of VMware's support for open source development and community.

A library which will add feature to serve your model over rest API

  • This will allow users to make ORM query based on any models present in the django app
  • This will ask user to provide request in defined format and will serve the API response as json data
  • This will allow users to make filter, selection, ordering, slicing and count of model objects

As of today we only support for django, will add support for sqlalchemy soon.

License

bridgeql is release under the BSD-2 license, see the LICENSE file.

SPDX-License-Identifier: BSD-2-Clause

Django Integration

Installation

You can install it directly from pypi.org using

pip install bridgeql

The bridgeql library can be integrated to the Django app by editing settings file by including bridgeql in the settings.INSTALLED_APPS variable. Another change required is to add a url to your existing project as

    projectname/projectname/settings.py
INSTALLED_APPS = [
    ...
    'bridgeql',
    ...
    ]

URLs Configuration

In your project you can edit urls.py, to include the bridgeql urls.

from bridgeql.django import urls as bridgeql_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 an API like follows:

    params = {
       'db_name': 'db1',
       'app_name': 'machine', # required
       'model_name': 'Machine', # required
       'filter': {
           'os__name': 'os-name-1'
        },
        'fields': ['ip', 'name', 'id'],
        'exclude': {
           'name': 'machine-name-11'
        },
        'order_by': ['ip'],
        'limit': 5,
        'offset': 10, # default 0
    }
    api_url = '<yoursite.com>/api/bridgeql/dj_read'
    resp = make_get_api_call(api_url, {'payload': json.dumps(params)})
    result = resp.json()

The above parameters will translate into running the model query for Machine model of machine django app.

Machine.objects.using('db1')
                .filter(os__name = 'os-name-1')
                .exclude(name = 'machine-name-11')
                .values(['ip', 'name', 'id'])
                .order_by('ip')[10:15] # offset: offset + limit

BridgeQL Settings

Settings available in BridgeQL and their default values

BRIDGEQL_RESTRICTED_MODELS

Default: {} (Empty dictionary)

Dictionary mapping app_label.model_name strings 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 to True, all the fields of that model will be restricted to lookup.

BRIDGEQL_RESTRICTED_MODELS = {
    'auth.User': True,
    'machine.OperatingSystem': ['license_key'],
}

BRIDGEQL_AUTHENTICATION_DECORATOR

Default: '' (Empty string)

Above setting allows you to use an authentication decorator to authenticate your client's requests. You can provide a custom authentication decorator whichever suits your application usecase, e.g login_required, same_subnet, etc.

Default value for BRIDGEQL_AUTHENTICATION_DECORATOR will allow you to access API without authentication.

BRIDGEQL_AUTHENTICATION_DECORATOR = 'bridgeql.auth.basic_auth'

bridgeql.auth.basic_auth is available as a basic authentication method where you can pass authorization header as Authorization: Basic base64(username:password) for each request.


Build & Run

  1. make test
  2. source venv/bin/activate && tox
  3. python -m pip install --upgrade build
  4. python -m build

Documentation

Contributing

The bridgeql project team welcomes contributions from the community. Before you start working with bridgeql, please read our Developer 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 to CONTRIBUTING_DCO.md.

Authors

Created and maintained by
Piyus Kumar piyusk@vmware.com
Priyank Singh priyanksi@vmware.com

Copyright © 2023, VMware, Inc. All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bridgeql-0.1.10.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bridgeql-0.1.10-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file bridgeql-0.1.10.tar.gz.

File metadata

  • Download URL: bridgeql-0.1.10.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for bridgeql-0.1.10.tar.gz
Algorithm Hash digest
SHA256 f3aa5a45173c071e05322b03b197a13ea770875647592ba465e36463d340fe17
MD5 aef9c7ed52cb3c1309ceee287e0b0b46
BLAKE2b-256 a36e335336e47926bfd46f4ed844743e933fa53e6aba3a7a48016e5ca257ab1d

See more details on using hashes here.

File details

Details for the file bridgeql-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: bridgeql-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for bridgeql-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 44fbcfc947408b7f1de7eb9275168e89c0f2bf2bbf2d938d6e3a9db6f4184214
MD5 d23a17ee4f72d3327114c5ad4594e04e
BLAKE2b-256 216a9967ef505fbb65b9b5d5b5e127c26f3002471ff5792fe8de8a10cdce59d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page