Skip to main content

Flask extension to integrate PocketBase

Project description

Flask Pocket

FlaskPocket is a Flask extension that integrates PocketBase, a backend service.

Prerequisites

Installation

pip install flask-pocket

Or install from the cloned repository:

git clone https://github.com/codewithmpia/flask_pocket.git
cd flask_pocket
pip install .

Configuration

Add the following configurations to your Flask app:

app.config["POCKETBASE_URL"] = "your_pocketbase_url"
app.config["POCKETBASE_ADMIN_EMAIL"] = "your_admin_email"
app.config["POCKETBASE_ADMIN_PASSWORD"] = "your_admin_password"

Usage

from flask import Flask
from flask_pocket import FlaskPocket

app = Flask(__name__)

app.config["POCKETBASE_URL"] = "your_pocketbase_url"
app.config["POCKETBASE_ADMIN_EMAIL"] = "your_admin_email"
app.config["POCKETBASE_ADMIN_PASSWORD"] = "your_admin_password"
pocket = FlaskPocket(app)

Queries

Get All Objects

try:
    posts = pocket.collection("posts").get_full_list()
except pocket.ClientResponseError as e:
    # Handle error
    print(f"Error: {e}")

Get One Object

try:
    post = pocket.collection("posts").get_one(post_id)
    # Generate image url
    image_url = pocket.client.get_file_url(post, post.image)
except pocket.ClientResponseError as e:
    # Handle error
    print(f"Error: {e}")

Create

try:
    pocket.collection("contacts").create({
        "name": name,
        "email": email,
        "message": message
    })
    return redirect(url_for("contact"))
except pocket.ClientResponseError as e:
    # Handle error
    print(f"Error: {e}")

Edit

try:
    pocket.collection("contacts").update(contact_id, {
        "name": new_name,
        "email": new_email,
        "message": new_message
    })
except pocket.ClientResponseError as e:
    # Handle error
    print(f"Error: {e}")

Delete

try:
    pocket.collection("contacts").delete(contact_id)
except pocket.ClientResponseError as e:
    # Handle error
    print(f"Error: {e}")

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributions

Contributions are welcome.

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

flask_pocket-1.0.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

flask_pocket-1.0.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file flask_pocket-1.0.2.tar.gz.

File metadata

  • Download URL: flask_pocket-1.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for flask_pocket-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8c86bf141229d32a06ae12ebde5f37c14257911fc90067f6bde68b8a51f332bd
MD5 9f3ae3c5c2987da4551e9d5c1ccfa739
BLAKE2b-256 50831d2f5ed408cbabbed4280bb0001bb3edcf5500f98a523b7a2b7816c0551c

See more details on using hashes here.

File details

Details for the file flask_pocket-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: flask_pocket-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for flask_pocket-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cb43528cd61928aaa31a29d22117806c572e8f59be24d648e8f8b2ed673d6fe5
MD5 d03dc4668b46656a16c1b63e661292e0
BLAKE2b-256 525950d0650cbda266b2bc20cd1c22e144780c0f6792307aeef8fd36cd1ab6ed

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