Skip to main content

PocketBase SDK for python.

Project description

PocketBase Python SDK

Tests Coverage Status

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:

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.

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

pocketbase-0.16.0.tar.gz (46.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pocketbase-0.16.0-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file pocketbase-0.16.0.tar.gz.

File metadata

  • Download URL: pocketbase-0.16.0.tar.gz
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","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}

File hashes

Hashes for pocketbase-0.16.0.tar.gz
Algorithm Hash digest
SHA256 68705a004273a51336d30cb200238ed4f39e665796a391be305dde6539ee1e16
MD5 e43066fa6ae1a7521a4090d550e9dd78
BLAKE2b-256 4114166460e92dd5a582d3a584990b22dbcabcd520174d4ec88e31e07b997ed7

See more details on using hashes here.

File details

Details for the file pocketbase-0.16.0-py3-none-any.whl.

File metadata

  • Download URL: pocketbase-0.16.0-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","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}

File hashes

Hashes for pocketbase-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7dfbb08fa72bb5e4483d00c0cb2aea576b6fcc00ac9f74f32d0f0fa11ce4779b
MD5 26597adf287bd30fa1e0708e38f75ea8
BLAKE2b-256 86901d263fed35a19db09f4504c3004eab1409a229114174e1920a7ac7e6302d

See more details on using hashes here.

Supported by

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