Skip to main content

A Python package for library management analytics

Project description

Library Analytics

A Python package for library management analytics, designed to work seamlessly with Django-based library systems.

Features

  • Inventory Summary: Get real-time statistics on total books, available stock, and out-of-stock items
  • Checkout Reports: Track weekly/daily checkout trends
  • Popular Books: Identify most and least borrowed books
  • Overdue Tracking: Monitor overdue book returns
  • Genre Analysis: Analyze book distribution by genre
  • User Activity: Track individual user borrowing patterns

Installation

pip install library-analytics

For Django integration:

pip install library-analytics[django]

Quick Start

With Django

from library_analytics import LibraryAnalytics

# Initialize (auto-detects Django models)
analytics = LibraryAnalytics()

# Get inventory summary
summary = analytics.inventory_summary()
print(f"Total books: {summary['total_books']}")
print(f"Available: {summary['stock_in']}")
print(f"Out of stock: {summary['stock_out']}")

# Get weekly checkout report
weekly_checkouts = analytics.weekly_checkout_report(days=7)
print(f"Checkouts this week: {weekly_checkouts}")

# Get popular books
popular = analytics.popular_books(limit=10)
for book in popular:
    print(f"{book.title} - {book.checkout_count} checkouts")

With Custom Models

from library_analytics import LibraryAnalytics
from myapp.models import Book, Transaction
from django.utils import timezone

# Initialize with custom models
analytics = LibraryAnalytics(
    book_model=Book,
    transaction_model=Transaction,
    timezone_module=timezone
)

# Use the same methods as above
summary = analytics.inventory_summary()

Available Methods

inventory_summary()

Returns a dictionary with inventory statistics:

  • total_books: Total number of unique book titles
  • stock_in: Books currently available for checkout
  • stock_out: Books currently out of stock
  • total_copies: Total number of book copies

weekly_checkout_report(days=7)

Returns the number of checkouts in the last N days.

popular_books(limit=10)

Returns a list of most frequently borrowed books.

least_borrowed_books(limit=10)

Returns a list of least frequently borrowed books.

overdue_books()

Returns a list of transactions with overdue books.

genre_distribution()

Returns a dictionary mapping genres to book counts.

user_activity(user_id)

Returns borrowing statistics for a specific user.

Django Integration

The package automatically detects Django models named BookLog and Transaction from a books app.

Your models should have the following structure:

class BookLog(models.Model):
    book_id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=200)
    author = models.CharField(max_length=100)
    genre = models.CharField(max_length=50)
    number_of_books_available = models.IntegerField(default=0)
    # ... other fields

class Transaction(models.Model):
    transaction_id = models.AutoField(primary_key=True)
    book = models.ForeignKey(BookLog, related_name='transactions', on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    date_of_checkout = models.DateField()
    expected_return_date = models.DateField()
    actual_return_date = models.DateField(null=True, blank=True)
    is_returned = models.BooleanField(default=False)
    # ... other fields

Requirements

  • Python >= 3.8
  • Django >= 4.0 (optional, for Django integration)

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

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

library_analytics-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

library_analytics-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: library_analytics-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for library_analytics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 315dd868f7fb9c7c5f4ffb53ead16dbe91133878ebe8939a3f2d941c83fb0f6b
MD5 d2b153a6e7805e51f263001da6985592
BLAKE2b-256 202fa21a39f26d32b89ae25ad9c536397214b65a71ab0c0446953d588e39751b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for library_analytics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 149596381324b857553c4d6404cdfe854c27ffffd2e525c0e88a132a1b8b3d49
MD5 59d2b09f8b889acd7dfcffb0905b394d
BLAKE2b-256 3afe03108bd7533e904600460c92735ce9180ba5d87474393debe9f14c62b107

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