pycartnext is a simple shopping cart service built using FastAPI and Redis for caching. It provides basic cart management functionalities like adding/removing items, modifying quantities, and applying discounts.
- Add, remove, and modify items in the shopping cart
- Apply discounts to the cart
- Use Redis for caching cart data
- Easy-to-use service interface for managing the cart
Ensure you have Python 3.10+ and Redis installed.
-
Install dependencies using Poetry:
pip install pycartnext
-
Set up Redis:
- Install Redis locally or use a Redis cloud service.
- Make sure Redis is running on
redis://127.0.0.1:6379
.
-
Example:
- Check example folder how to use.
The CartService
class handles all cart-related operations. Here's how you can use it:
-
Create a CartService instance:
from cart_service import CartService cart_service = CartService(redis_url="redis://127.0.0.1:6379")
-
Add an item to the cart:
cart_service.add_item(title="Product A", price=100.0, quantity=2)
-
Remove an item from the cart:
cart_service.remove_item(item_id=1)
-
Increment item quantity:
cart_service.increment_item_quantity(item_id=1)
-
Decrement item quantity:
cart_service.decrement_item_quantity(item_id=1)
-
Apply a discount to the cart:
cart_service.apply_discount(discount_percentage=10)
-
Clear the entire cart:
cart_service.clear_cart()
-
View the current cart:
cart = cart_service.get_cart() print(cart)
This project is licensed under the MIT License - see the LICENSE file for details.