A Python library to easily build CubicWeb clients
Project description
Summary
A Python library to easily build CubicWeb clients:
execute RQL queries remotely (using rqlcontroller),
access instances that requires authentication (using signedrequest).
Requirements
client side:
requests (>= 2.0)
server side:
CubicWeb (>= 3.18.3) with the cubes rqlcontroller and signedrequest
Using signed requests
Once the cube signedrequest is added, in the WebUI:
View a CWUser and click the action add an AuthToken
Give an identifier to the token and make it enabled
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:
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:
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(query)
data = resp.json()
Using builders helpers, authenticating with kerberos:
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.