Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vaphes/pocketbase
PocketBase client SDK for python
https://github.com/vaphes/pocketbase
client database pocketbase python sdk
Last synced: 15 days ago
JSON representation
PocketBase client SDK for python
- Host: GitHub
- URL: https://github.com/vaphes/pocketbase
- Owner: vaphes
- License: mit
- Created: 2022-09-19T14:53:14.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-26T15:28:16.000Z (7 months ago)
- Last Synced: 2024-05-09T13:34:06.479Z (6 months ago)
- Topics: client, database, pocketbase, python, sdk
- Language: Python
- Homepage: https://pypi.org/project/pocketbase/
- Size: 139 KB
- Stars: 230
- Watchers: 4
- Forks: 27
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-pocketbase - GitHub
- awesome-pocketbase - GitHub
- awesome-pocketbase - Python (Sync) - PocketBase Client in Python. ![GitHub Repo stars](https://img.shields.io/github/stars/vaphes/pocketbase) (Unofficial PocketBase Clients (SDKs))
README
# PocketBase Python SDK
[![Tests](https://github.com/vaphes/pocketbase/actions/workflows/tests.yml/badge.svg)](https://github.com/vaphes/pocketbase/actions/workflows/tests.yml)
[![Coverage Status](https://coveralls.io/repos/github/vaphes/pocketbase/badge.svg?branch=master)](https://coveralls.io/github/vaphes/pocketbase?branch=master)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:
```shell
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!
```python
from pocketbase import PocketBase # Client also works the same
from pocketbase.client import FileUploadclient = PocketBase('http://127.0.0.1:8090')
# authenticate as regular user
user_data = client.collection("users").auth_with_password(
"[email protected]", "0123456789")
# check if user token is valid
user_data.is_valid# or as admin
admin_data = client.admins.auth_with_password("[email protected]", "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](https://pocketbase.io/docs/api-authentication). Just remember to 'pythonize it' 🙃.## Development
These are the requirements for local development:
* Python 3.9+
* Poetry (https://python-poetry.org/)You can install locally:
```shell
poetry install
```Or can build and generate a package:
```shell
poetry build
```But if you are using only PIP, use this command:
```shell
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:
```bash
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
```
## LicenseThe PocketBase Python SDK is MIT licensed code.