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.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

firebase_cart-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: firebase_cart-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 de0a8d6fe964efbc8de626520020d948e95850fbbb11aa228780eb0cb3dac5c6
MD5 01253cb2f2cc0ff19e28c9110c4af04f
BLAKE2b-256 eca367fb37e8e3f8b1002e64c523fc3b5ae92d0c34f9230c9874c65cee7b85c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for firebase_cart-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95a00e95cd2f8d0fc6b59d11e1aeba0bbadd94de6871bddd61da229556658242
MD5 6a2f94022fba0c3bf9c3507afb1f2ec2
BLAKE2b-256 d4c4e2fad96b1540d600d06d66a0f511185249a9ebf1adfc3d2144c16567c089

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