Skip to main content

Core business logic utilities for validating, pricing, and checking availability of badminton, table tennis, and tennis turf slots.

Project description

turfslot-utils

Core business logic helpers for booking badminton, table tennis, and tennis turf slots.
The package provides reusable dataclasses and services to validate slots, detect clashes, and compute prices so that any Python application (web, CLI, or automation) can reuse the same rules.

Installation

Once released to PyPI:

pip install turfslot-utils

For local development from this repository:

pip install .

Quick start

from datetime import datetime, timezone

from turfslot_utils import (
    Court,
    SlotPriceCalculator,
    SlotRangeValidator,
    SportAvailabilityChecker,
    CourtNotAvailableError,
)

court = Court(
    court_id="C1",
    sport_type="BADMINTON",
    name="Smash Arena",
    hourly_rate=400,
)

validator = SlotRangeValidator()
slot = validator.validate(
    sport_type="BADMINTON",
    court_id="C1",
    start_time=datetime(2025, 1, 10, 9, 0, tzinfo=timezone.utc),
    end_time=datetime(2025, 1, 10, 11, 0, tzinfo=timezone.utc),
)

checker = SportAvailabilityChecker()
existing_bookings = []  # Populate from your storage layer
try:
    checker.check_availability(slot, existing_bookings)
except CourtNotAvailableError:
    print("Court already booked!")
else:
    total = SlotPriceCalculator().calculate_price(slot, court)
    print(f"Booking confirmed. Price: INR {total}")

Testing

python -m pytest

Building and publishing

python -m pip install --upgrade build twine
python -m build
# TestPyPI upload
python -m twine upload --repository testpypi dist/*
# PyPI upload (set TWINE_PASSWORD or use keyring)
python -m twine upload dist/*

Keep credentials outside source control and pass them via environment variables or a secure keyring.

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

turfslot_utils-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

turfslot_utils-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for turfslot_utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 08f94942ea3021fc1e3205aebb4dbfc4c72013e19fa2ae3a431c9471d4c2f47b
MD5 7127462cb9a7cc73b26344b233252f3b
BLAKE2b-256 aecccc67c821acc2612e0bdcaa08011f81257e8d6f348c27b16c8ce363a709e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: turfslot_utils-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for turfslot_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 138f7e4d5d4a605af44484f4c45b8c699427c22996806916a1909500ced856a9
MD5 c532801782c99ddb5455297a6604a826
BLAKE2b-256 757de29d861dcb9cfb3cc39b24bc7f483ce304af1ea25e300b5981b88659fc02

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