Python client for the reactive backend-as-a-service Convex.
Actively maintained. Last release 3 months ago, commits in 21 of the last 26 weeks. A safe choice.
pip install convexConvex
The official Python client for Convex.
Write and read data from a Convex backend with queries, mutations, and actions. Get up and running at docs.convex.dev.
Installation:
pip install convex
Basic usage:
>>> from convex import ConvexClient
>>> client = ConvexClient('https://example-lion-123.convex.cloud')
>>> messages = client.query("messages:list")
>>> from pprint import pprint
>>> pprint(messages)
[{'_creationTime': 1668107495676.2854,
'_id': '2sh2c7pn6nyvkexbdsfj66vd9h5q3hg',
'author': 'Tom',
'body': 'Have you tried Convex?'},
{'_creationTime': 1668107497732.2295,
'_id': '1f053fgh2tt2fc93mw3sn2x09h5bj08',
'author': 'Sarah',
'body': "Yeah, it's working pretty well for me."}]
>>> client.mutation("messages:send", dict(author="Me", body="Hello!"))
>>> for messages in client.subscribe("messages:list", {}):
... print(len(messages))
...
3
<this for loop lasts until you break out with ctrl-c>
To find the url of your convex backend, open the deployment you want to work with in the appropriate project in the Convex dashboard and click "Settings" where the Deployment URL should be visible. To find out which queries, mutations, and actions are available check the Functions pane in the dashboard.
To see logs emitted from Convex functions, set the debug mode to True.
>>> client.set_debug(True)
To provide authentication for function execution, call set_auth().
>>> client.set_auth("token-from-authetication-flow")
To authenticate as an admin, allowing you to run internal functions not exposed
to the public internet, call set_admin_auth().
>>> client.set_admin_auth("admin-key")
Join us on Discord to get your questions answered or share what you're doing with Convex. If you're just getting started, see https://docs.convex.dev to see how to quickly spin up a backend that does everything you need in the Convex cloud.