A demonstration package for teaching Python best practices. This package implements a simple book management system to illustrate:
- Clean code principles
- Proper package structure
- Good naming conventions
- Comprehensive documentation
- Type hints
- Testing practices
bookstore/
├── src/
│ └── bookstore/
│ ├── __init__.py
│ ├── models/
│ │ ├── __init__.py
│ │ └── book.py
│ ├── repositories/
│ │ ├── __init__.py
│ │ └── book_repository.py
│ └── exceptions/
│ ├── __init__.py
│ └── book_exceptions.py
└── tests/
└── test_book.py
For development:
pip install -e ".[dev]"
from bookstore.models.book import Book
from bookstore.repositories.book_repository import BookRepository
# Create a new book
book = Book(
isbn="978-0-7475-3269-9",
title="Harry Potter and the Philosopher's Stone",
author="J.K. Rowling",
publication_year=1997
)
# Store the book
repository = BookRepository()
repository.add_book(book)
# Retrieve a book
found_book = repository.get_book_by_isbn("978-0-7475-3269-9")
- Clear Module Structure: Separation of concerns between models, repositories, and exceptions
- Type Hints: All functions include proper type annotations
- Documentation: Google-style docstrings with examples
- Error Handling: Custom exceptions and proper error messages
- Testing: Comprehensive unit tests with pytest
- Clean Code: Short, focused methods with clear responsibilities
This is an educational project. Feel free to fork and experiment, but we have some tasks for you to complete.
Add Book Categories/Genres
Branch name: feature/book-categories
Scope:
- Add category field to Book class
- Add category validation
- Update repository to search by category
PR Learning Points:
- Single responsibility principle
- Database schema changes
- Test coverage for new field
Add Book Search Functionality
Branch name: feature/search-books
Scope:
- Add search by title/author
- Implement fuzzy matching
- Add search result pagination
PR Learning Points:
- Algorithm implementation
- Performance considerations
- Documentation of search parameters
Add Book rating
Branch name: feature/book-ratings
Scope:
- Add Rating class
- Implement rating statistics
- Add rating constraints (1-5 stars)
PR Learning Points:
- Relationship between models
- Data validation
- Statistical calculations
Add Book Import/Export
Branch name: feature/import-export
Scope:
- CSV import/export
- JSON serialization
- Data validation
PR Learning Points:
- File handling
- Data formats
- Error handling
It is important to know how to hadle and operate with branches.
Please refer to the CONTRIBUTING.md file for more information on how to contribute to this project.
Please refer to the PR Template on the expected format for PRs.
This project uses GitHub Actions for continuous integration and deployment:
- Testing: Automated tests run on multiple Python versions (3.8-3.11)
- Code Coverage: Coverage reports are uploaded to Codecov
- Linting: Code quality checks using Black, isort, mypy, and pylint
- Publishing: Automatic package publishing to PyPI on new releases
Before merging a PR, ensure all status checks pass:
- All tests pass across Python versions
- Code coverage meets minimum threshold (90%)
- Code follows style guidelines (Black, isort)
- No type checking errors (mypy)
- No linting issues (pylint)