A comprehensive Python library for building scalable and secure e-commerce applications
Project description
EcomLib
A comprehensive Python library for building scalable and secure e-commerce applications. EcomLib provides production-ready tools for inventory management, order processing, payment handling, and more.
โจ Features
๐ช Inventory Management
- Product & Variant Management: Full CRUD operations with hierarchical categories
- Real-time Stock Tracking: Multi-location inventory with automatic low-stock alerts
- Stock Movements: Track purchases, sales, returns, adjustments, and transfers
- Thread-safe Operations: Built-in locking for concurrent access
- Bulk Operations: Efficient batch processing for high-volume updates
๐ Shopping Cart
- Add/remove/update items with ease
- Automatic price calculations
- Discount and coupon support
- Persistent cart sessions
- Cart abandonment tracking
๐ฆ Order Management
- Complete order lifecycle management
- Status tracking (pending โ processing โ shipped โ delivered)
- Payment status integration
- Refund and return handling
- Order history and search
๐ณ Payment Processing
- Multiple payment gateway support (Stripe, PayPal, etc.)
- Secure payment handling
- Webhook integration
- Refund processing
- Transaction history
๐ Security
- JWT-based authentication
- Role-based access control (RBAC)
- Password hashing with bcrypt
- Input validation and sanitization
- CSRF protection
๐ Additional Features
- Geolocation services
- Address validation
- Tax calculation
- Shipping cost calculation
- Multi-currency support
๐ Quick Start
Installation
pip install ecomlib
Basic Usage
from ecomlib.inventory import Product, ProductManager, InventoryManager, StockMovement, StockMovementType
from decimal import Decimal
# Initialize managers
product_manager = ProductManager()
inventory_manager = InventoryManager()
# Create a product
product = Product(
name="Wireless Headphones",
description="Premium noise-canceling headphones",
price=199.99,
sku="WH-001",
category="electronics"
)
product = product_manager.add_product(product)
# Add stock
movement = StockMovement(
product_id=product.id,
quantity=50,
movement_type=StockMovementType.PURCHASE,
reference_id="PO-001"
)
inventory_manager.record_movement(movement)
# Check inventory
level = inventory_manager.get_inventory_level(product.id)
print(f"Current stock: {level.available_quantity} units")
# Process a sale
sale = StockMovement(
product_id=product.id,
quantity=-5,
movement_type=StockMovementType.SALE,
reference_id="ORDER-001"
)
inventory_manager.record_movement(sale)
๐ Documentation
Core Modules
Inventory Management
from ecomlib.inventory import InventoryManager, ProductManager
# Product operations
product_manager = ProductManager()
product = product_manager.add_product(product_data)
product = product_manager.get_product(product_id)
products = product_manager.search_products(query="headphones")
# Inventory operations
inventory = InventoryManager()
inventory.record_movement(movement)
level = inventory.get_inventory_level(product_id)
low_stock = inventory.check_low_stock_items(threshold=10)
Shopping Cart
from ecomlib.cart import ShoppingCart
cart = ShoppingCart()
cart.add_item(
product_id="prod_123",
quantity=2,
price=19.99,
attributes={'name': 'Product Name', 'sku': 'SKU-001'}
)
total = cart.get_total()
cart.apply_coupon("SAVE10", 10.00)
Order Management
from ecomlib.order import OrderManager, OrderStatus
orders = OrderManager()
order = orders.create_order(
customer_id="customer_123",
items=[{
"product_id": "prod_123",
"quantity": 2,
"unit_price": 19.99,
"name": "Product Name",
"sku": "SKU-001"
}],
shipping_address=address_data
)
# Update order status
order.update_status(OrderStatus.PROCESSING)
Authentication
from ecomlib.auth import AuthManager
auth = AuthManager()
# Register user
user = auth.register_user(
username="johndoe",
password="secure_password",
email="john@example.com"
)
# Login
token = auth.login("johndoe", "secure_password")
# Verify token
payload = auth.verify_token(token)
๐งช Testing
# Run all tests
bash run_all_tests.sh
# Run specific test suite
pytest tests/test_inventory.py -v
# Run with coverage
pytest --cov=ecomlib --cov-report=html
๐ ๏ธ Development
Setup Development Environment
# Clone the repository
git clone https://github.com/Shamsulhaq/ecomlib.git
cd ecomlib
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e .
pip install -r requirements-dev.txt
# Run tests
bash run_all_tests.sh
Project Structure
ecomlib/
โโโ ecomlib/ # Main package
โ โโโ __init__.py
โ โโโ auth.py # Authentication
โ โโโ cart.py # Shopping cart
โ โโโ exceptions.py # Custom exceptions
โ โโโ inventory.py # Inventory management
โ โโโ order.py # Order management
โ โโโ payment.py # Payment processing
โ โโโ security.py # Security utilities
โโโ tests/ # Test suite
โ โโโ test_auth.py
โ โโโ test_cart.py
โ โโโ test_inventory.py
โ โโโ test_order.py
โโโ docs/ # Documentation
โโโ examples/ # Usage examples
โโโ CONTRIBUTING.md # Contribution guidelines
โโโ README.md # This file
โโโ requirements.txt # Production dependencies
โโโ requirements-dev.txt # Development dependencies
โโโ setup.py # Package configuration
๐ API Reference
Exception Handling
from ecomlib.exceptions import (
InsufficientStockError,
ProductNotFoundError,
InvalidQuantityError
)
try:
inventory.record_movement(sale_movement)
except InsufficientStockError as e:
print(f"Not enough stock: {e}")
# Handle out of stock scenario
except ProductNotFoundError as e:
print(f"Product not found: {e}")
# Handle missing product
Type Hints
All public APIs include type hints for better IDE support:
def record_movement(
self,
movement: StockMovement
) -> StockMovement:
"""Record a stock movement."""
pass
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Quick Contribution Steps
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests
- Run tests (
bash run_all_tests.sh) - Commit (
git commit -m 'feat: add amazing feature') - Push (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Thanks to all contributors who have helped improve EcomLib
- Built with โค๏ธ for the e-commerce community
๐ง Contact
- GitHub: @Shamsulhaq
- Issues: GitHub Issues
- Discussions: GitHub Discussions
๐บ๏ธ Roadmap
- GraphQL API support
- Async/await support
- Redis caching integration
- Elasticsearch integration
- Admin dashboard
- REST API framework integration (Django, Flask, FastAPI)
- Webhook management system
- Advanced analytics and reporting
โญ Star History
If you find EcomLib useful, please consider giving it a star on GitHub!
Made with โค๏ธ by the EcomLib Team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ecomlib-1.0.0.tar.gz.
File metadata
- Download URL: ecomlib-1.0.0.tar.gz
- Upload date:
- Size: 59.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7a817a11a86fa1b6cb4e478a2d4b995c0e928aac0fc5321f5a212219b194c52
|
|
| MD5 |
a098224fbfa51fd628a1d8878963b3a7
|
|
| BLAKE2b-256 |
1e59eea51c78785611dba13dca1542b37b17e8584ed75e6f8560fd20d1ee2b2a
|
File details
Details for the file ecomlib-1.0.0-py2.py3-none-any.whl.
File metadata
- Download URL: ecomlib-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 53.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08fe01f2470b2893bcbf8ac4aaf71256f9b6d2b1be2f0899859cf253f5df185a
|
|
| MD5 |
a5efd2253c23e98474c91f9e5f36c7d2
|
|
| BLAKE2b-256 |
e78e294f98d0b6ecb38012e6f2777591cf98fd5c8c73391fa40e17132b49bb93
|