Skip to main content

A comprehensive Python library for building scalable and secure e-commerce applications

Project description

EcomLib

Python Version License Tests

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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests
  5. Run tests (bash run_all_tests.sh)
  6. Commit (git commit -m 'feat: add amazing feature')
  7. Push (git push origin feature/amazing-feature)
  8. 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

๐Ÿ—บ๏ธ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ecomlib-1.0.0.tar.gz (59.7 kB view details)

Uploaded Source

Built Distribution

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

ecomlib-1.0.0-py2.py3-none-any.whl (53.6 kB view details)

Uploaded Python 2Python 3

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

Hashes for ecomlib-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c7a817a11a86fa1b6cb4e478a2d4b995c0e928aac0fc5321f5a212219b194c52
MD5 a098224fbfa51fd628a1d8878963b3a7
BLAKE2b-256 1e59eea51c78785611dba13dca1542b37b17e8584ed75e6f8560fd20d1ee2b2a

See more details on using hashes here.

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

Hashes for ecomlib-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 08fe01f2470b2893bcbf8ac4aaf71256f9b6d2b1be2f0899859cf253f5df185a
MD5 a5efd2253c23e98474c91f9e5f36c7d2
BLAKE2b-256 e78e294f98d0b6ecb38012e6f2777591cf98fd5c8c73391fa40e17132b49bb93

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