Skip to main content

A Python package for interacting with PocketBase

Project description

PocketBase Python Client

A Python client for interacting with PocketBase, a backend for your next SaaS and Mobile app.

Installation

To install the PocketBase Python client, use pip:

pip install pocketpybase

Usage

First, import and initialize the PocketBase client:

from pocketbase import PocketBase

pb = PocketBase('https://your-pocketbase-url.com', 'your_username', 'your_password')

Records

Creating a record

record = {
    'field1': 'value1',
    'field2': 'value2'
}
created_record = pb.create_record('your_collection_name', record, token=None, expand="", fields="")

Getting all records

records = pb.get_all_records('your_collection_name', token=None, page=1, perPage=30, sort="", filter="", expand="", fields="", skipTotal=False)

Getting a record by ID

record = pb.get_record_by_id('your_collection_name', 'record_id', token=None, expand="", fields="")

Updating a record

updated_record = {
    'field1': 'new_value1',
    'field2': 'new_value2'
}
pb.update_record('your_collection_name', 'record_id', updated_record, token=None, expand="", fields="")

Deleting a record

pb.delete_record('your_collection_name', 'record_id', token=None)

Collections

Creating a collection

collection_name = 'new_collection'
db_type = 'base'
schema = [
    {
        'name': 'field1',
        'type': 'text',
        'required': True
    },
    {
        'name': 'field2',
        'type': 'number',
        'required': False
    }
]
pb.create_collection(collection_name, db_type, schema, fields="")

Listing collections

collections = pb.list_collections(page=1, perPage=30, sort="", filter="", fields="", skipTotal=False)

Transactions

@pb.transaction("test")
def update_test(collection, record_id, increment):
    record = collection.get_record_by_id(record_id)
    record["test"] = record.get("test", 0) + increment
    updated_record = collection.update_record(record_id, record)
    return updated_record

Authentication

Getting an authentication token

token = pb.get_token()

Refreshing an authentication token

token = pb.auth_refresh(token)

Features

  • Create, read, update, and delete records
  • Create and manage collections
  • Authenticate and retrieve tokens
  • Support for pagination, sorting, filtering, and field selection
  • Easily extensible for additional PocketBase features

Parameters

Most methods support the following optional parameters:

  • token: Authentication token
  • page: Page number for pagination
  • perPage: Number of items per page
  • sort: Sorting criteria
  • filter: Filtering criteria
  • expand: Related collections to expand
  • fields: Specific fields to return
  • skipTotal: Whether to skip total count calculation

Dependencies

  • httpx

License

MIT License

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

pocketpybase-0.1.9.5.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

pocketpybase-0.1.9.5-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pocketpybase-0.1.9.5.tar.gz.

File metadata

  • Download URL: pocketpybase-0.1.9.5.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.13

File hashes

Hashes for pocketpybase-0.1.9.5.tar.gz
Algorithm Hash digest
SHA256 8d2b589a0eb4c76a8d941c2aa8b36a3880babe31204d88c649926c704a152a28
MD5 493f1d10be34cfac81871063d30ea9f0
BLAKE2b-256 ccfdd06694c48881968ed1049e0dc67a99031e988fc7cb249045898931443b1d

See more details on using hashes here.

File details

Details for the file pocketpybase-0.1.9.5-py3-none-any.whl.

File metadata

  • Download URL: pocketpybase-0.1.9.5-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.13

File hashes

Hashes for pocketpybase-0.1.9.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7a560bbaa26073cbcd0a8d203474901f58393260710f1f18aa89d470e1fb9fc2
MD5 820f7f1b7bb2b76181301b5357a91b64
BLAKE2b-256 87b1b4e331cce11b50bfcf7f91164eb4892417b4da5036e2cc3a8fee38035d34

See more details on using hashes here.

Supported by

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