Skip to main content

A Firebase-based cart package for Python applications

Project description

Firebase Cart

A Firebase-based cart package for Python applications.

Installation

pip install firebase_cart

Usage

from firebase_cart import CartHandler, CartItem, FirebaseConfig

# Initialize with your Firebase credentials
firebase_config = FirebaseConfig(
    credentials={
        "type": "service_account",
        "project_id": "your-project-id",
        "private_key_id": "your-private-key-id",
        "private_key": "your-private-key",
        # ... other credential fields ...
    },
    database_url="https://your-project-id.firebaseio.com"  # Optional
)

cart_handler = CartHandler(firebase_config)

# Add item to cart
item = CartItem(product_id="123", quantity=2)
cart_handler.add_to_cart("user123", item)

# Get cart
cart = cart_handler.get_cart("user123")

# Update cart
cart.items.append(CartItem(product_id="456", quantity=1))
cart_handler.update_cart(cart)

# Clear cart
cart_handler.clear_cart("user123")

API Reference

CartHandler

  • __init__(config: FirebaseConfig): Initialize the CartHandler with Firebase configuration.
  • add_to_cart(user_id: str, item: CartItem, context: Optional[CartContext] = None): Add an item to the cart.
  • get_cart(user_id: str) -> Optional[Cart]: Retrieve a user's cart.
  • update_cart(cart: Cart): Update an entire cart.
  • clear_cart(user_id: str): Clear a user's cart.

CartItem

  • product_id: str: The ID of the product.
  • quantity: int: The quantity of the product.

CartContext

  • ip: Optional[str]: The IP address of the user.
  • user_agent: Optional[str]: The user agent of the client.
  • additional_info: Optional[Dict[str, Any]]: Any additional context information.

Error Handling

The package raises FirebaseError for any Firebase-related errors. Handle these appropriately in your application.

Logging

The package logs important events and errors. Configure logging in your application to capture these logs.

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

firebase_cart-0.1.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

firebase_cart-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file firebase_cart-0.1.1.tar.gz.

File metadata

  • Download URL: firebase_cart-0.1.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for firebase_cart-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b86595eda39f72466b2574bd0512a5f8c6a8a4f2e0c8d604e27dadc009d9ea84
MD5 50831169855ecdf4b0e1687b9ce87cfd
BLAKE2b-256 aa27a724f4e0327440279c470e689f9ebb3acdb0e3a49bb4853f1962336d264b

See more details on using hashes here.

File details

Details for the file firebase_cart-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for firebase_cart-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2ac4a5d9b33258959581b4b95d76db82a8872e797c05faa56e66a6cd372b180
MD5 31414c1ec86ecd19f9d79cc499aee996
BLAKE2b-256 6de8a11d24a180f1badecc99ea664a6ffb7f3888f1bead01108eaa1e2cbf765f

See more details on using hashes here.

Supported by

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