Skip to main content

A Python library to easily build CubicWeb clients

Project description

Summary

A Python library to easily build CubicWeb clients:

Requirements

client side:

server side:

Using signed requests

Once the cube signedrequest is added, in the WebUI:

  1. View a CWUser and click the action add an AuthToken

  2. Give an identifier to the token and make it enabled

  3. Use the token identifier and the token in your source code

Using Kerberos

Just make sure Python-Kerberos and Requests-Kerberos are installed.

Examples

Simple read only query:

from cwclientlib import cwproxy

client = cwproxy.CWProxy('http://www.cubicweb.org/')
query = 'Any X WHERE X is Ticket, X concerns P, P name "cwclientlib"'
resp = client.rql(query)
data = resp.json()

Creating an entity, authenticating with signedrequest:

from cwclientlib import cwproxy

auth = cwproxy.SignedRequestAuth('my token', '6ed44d82172211e49d9777269ec78bae')
client = cwproxy.CWProxy('https://www.cubicweb.org/', auth)
queries = [('INSERT CWUser U: U login %(l)s, U upassword %(p)s',
            {'l': 'Babar', 'p': 'cubicweb rulez & 42'}), ]
resp = client.rqlio(queries)
data = resp.json()

Creating a file entity, authenticating with signedrequest:

from io import BytesIO
from cwclientlib import cwproxy

auth = cwproxy.SignedRequestAuth('my token', '6ed44d82172211e49d9777269ec78bae')
client = cwproxy.CWProxy('https://www.cubicweb.org/', auth)
queries = [('INSERT File F: F data %(content)s, F data_name %(fname)s',
            {'content': BytesIO('some binary data'), 'fname': 'toto.bin'})]
resp = client.rqlio(queries)
data = resp.json()

Using builders helpers, authenticating with kerberos:

from cwclientlib import cwproxy, builders
from requests_kerberos import HTTPKerberosAuth, OPTIONAL

auth = HTTPKerberosAuth(mutual_authentication=OPTIONAL)
client = cwproxy.CWProxy('https://www.cubicweb.org/', auth)
queries = [builders.create_entity('CWUser', login='Babar', password='secret'),
           builders.build_trinfo('__r0', 'disable', 'not yet activated'),
          ]
resp = client.rqlio(queries)
data = resp.json()

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

cwclientlib-0.2.0.tar.gz (15.5 kB view hashes)

Uploaded Source

Supported by

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