PocketBase Python SDK
Python client SDK for the PocketBase backend.
This is in early development, and at first is just a translation of the javascript lib using HTTPX.
Installation
Install PocketBase using PIP:
python3 -m pip install pocketbase
Usage
The rule of thumb here is just to use it as you would the javascript lib, but in a pythonic way of course!
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")
# check if user token is valid
user_data.is_valid
# or as admin
admin_data = client.admins.auth_with_password("test@example.com", "0123456789")
# check if admin token is valid
admin_data.is_valid
# 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. Just remember to 'pythonize it' 🙃.
Note: By default, camelCase (or any other key style) from the API is converted to snake_case in Python. You can keep the original keys by setting auto_snake_case=False when creating the client.
from pocketbase import Client
client = Client(auto_snake_case=False)
# Fields will keep their original names from the API
Development
These are the requirements for local development:
- Python 3.9+
- Poetry (https://python-poetry.org/)
You can install locally:
poetry install
Or can build and generate a package:
poetry build
But if you are using only PIP, use this command:
python3 -m pip install -e .
Tests
To execute the tests use this command:
poetry run pytest
Sandbox integration testing
A lot of real-world integration test against a sandboxed pocketbase instance will be included in the pytest when the sandbox is running (on 127.0.0.1:8090) to start the sandbox follow the following steps:
export TMP_EMAIL_DIR=`mktemp -d` # Export temp dir used for sendmail sandbox
bash ./tests/integration/pocketbase # Run the pocketbase sandbox (automatically downloads the latest pocketbase instance)
pytest # Run test including sandbox API integration tests
License
The PocketBase Python SDK is MIT licensed code.
Metadata
Release files for pocketbase 0.17.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pocketbase-0.17.3.tar.gz | 17.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pocketbase-0.17.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.9 kB
Release files / pocketbase-0.17.3.tar.gz
| Download URL | pocketbase-0.17.3.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11de4d412fddc98e72030fa78b395972eaa646c36c06aa2506d8a26cd251cb00
|
|
BLAKE2b-256 checksum How to use checksums |
8b9d613b0e70d9168f38706c9c7e83e7252609a05e77f0045bb78ac3ba1d4484
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pocketbase-0.17.3-py3-none-any.whl
| Download URL | pocketbase-0.17.3-py3-none-any.whl |
|---|---|
| Size | 29.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
44810514244b0c7260c5aba8c4fe78bed178ff10d0870c00aa67498cde397147
|
|
BLAKE2b-256 checksum How to use checksums |
a59d66bf04043a779ae8da403e6a302503cbefd0604cb362361b4d8868a5d3f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|