* fix services * Port of PR #6 to branch 0.8.0 (#7) * Switch from JSON to multipart file encoding for file upload File upload is detected when body data contains a value of class FileUpload Remaining JSON is converted to FormData Enitre message is sent as multipart * Switch from JSON to multipart file encoding for file upload (#6) File upload is detected when body data contains a value of class FileUpload Remaining JSON is converted to FormData Enitre message is sent as multipart * fix readme * fix client * Remove "@" chars (#11) * Remove "@" chars that led to empty collectionId, collectionName and expand * Make load method more generic * fix license --------- Co-authored-by: Paulo Coutinho <paulocoutinhox@gmail.com> Co-authored-by: Martin <mahe@quantentunnel.de> Co-authored-by: Eoin Fennessy <85010533+eoinfennessy@users.noreply.github.com>
53 lines
1.8 KiB
Markdown
53 lines
1.8 KiB
Markdown
# PocketBase Python SDK
|
|
|
|
[](https://github.com/vaphes/pocketbase/actions/workflows/tests.yml)
|
|
|
|
Python client SDK for the <a href="https://pocketbase.io/">PocketBase</a> backend.
|
|
|
|
This is in early development, and at first is just a translation of <a href="https://github.com/pocketbase/js-sdk">the javascript lib</a> using <a href="https://github.com/encode/httpx/">HTTPX</a>.
|
|
|
|
---
|
|
|
|
## Installation
|
|
|
|
Install PocketBase using pip:
|
|
|
|
```shell
|
|
$ pip install pocketbase
|
|
```
|
|
|
|
## Usage
|
|
|
|
The rule of thumb here is just to use it as you would <a href="https://github.com/pocketbase/js-sdk">the javascript lib</a>, but in a pythonic way of course!
|
|
|
|
```python
|
|
from pocketbase import PocketBase # Client also works the same
|
|
from pocketbase.client import FileUpload
|
|
|
|
client = PocketBase('http://127.0.0.1:8090')
|
|
|
|
# authenticate as regular user
|
|
user_data = client.collection("users").auth_with_password(
|
|
"user@example.com", "0123456789")
|
|
|
|
# or as admin
|
|
admin_data = client.admins.auth_with_password("test@example.com", "0123456789")
|
|
|
|
# list and filter "example" collection records
|
|
result = client.collection("example").get_list(
|
|
1, 20, {"filter": 'status = true && created > "2022-08-01 10:00:00"'})
|
|
|
|
# create record and upload file to image field
|
|
result = client.collection("example").create(
|
|
{
|
|
"status": "true",
|
|
"image": FileUpload(("image.png", open("image.png", "rb"))),
|
|
})
|
|
|
|
# and much more...
|
|
```
|
|
> More detailed API docs and copy-paste examples could be found in the [API documentation for each service](https://pocketbase.io/docs/api-authentication). Just remember to 'pythonize it' 🙃.
|
|
|
|
|
|
<p align="center"><i>The PocketBase Python SDK is <a href="https://github.com/vaphes/pocketbase/blob/master/LICENCE.txt">MIT licensed</a> code.</p>
|