Skip to main content

A demonstration package for teaching Python best practices

Project description

Bookstore Package

Tests Lint codecov PyPI version Google Slides

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

Project Structure

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

Installation

For development:

pip install -e ".[dev]"

Usage Example

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")

Development Practices Demonstrated

  1. Clear Module Structure: Separation of concerns between models, repositories, and exceptions
  2. Type Hints: All functions include proper type annotations
  3. Documentation: Google-style docstrings with examples
  4. Error Handling: Custom exceptions and proper error messages
  5. Testing: Comprehensive unit tests with pytest
  6. Clean Code: Short, focused methods with clear responsibilities

Contributing

This is an educational project. Feel free to fork and experiment, but we have some tasks for you to complete.

Tasks 1

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

Tasks 2

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

Tasks 3

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

Tasks 4

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

Branch handling

It is important to know how to hadle and operate with branches.

Contributing

Please refer to the CONTRIBUTING.md file for more information on how to contribute to this project.

PR Template

Please refer to the PR Template on the expected format for PRs.

Continuous Integration

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

Status Checks

Before merging a PR, ensure all status checks pass:

  1. All tests pass across Python versions
  2. Code coverage meets minimum threshold (90%)
  3. Code follows style guidelines (Black, isort)
  4. No type checking errors (mypy)
  5. No linting issues (pylint)

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

nelson_semtec_bookstore-0.1.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

nelson_semtec_bookstore-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nelson_semtec_bookstore-0.1.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for nelson_semtec_bookstore-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fb1281ad1aa6875a63dbba9270f6a67386f454d56ad5fa71587b0dcfde91a36f
MD5 0f3161236188d87781e710664265f29e
BLAKE2b-256 8ee446a349266e90cf7b5f3558236adbcbcc5cff514249f38b1b78bca0b56fd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelson_semtec_bookstore-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb8df74235ea772c67b8fa64086396ee142614ad0b8c5a6c15879140da67fe47
MD5 fcc37cd23664d6069448ae1f79ebb80b
BLAKE2b-256 da5ae90c06bfcabe6f6a9c07a2f94657a33a9d7cbdb4190188902077ef093df8

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