Skip to main content

django-availability

Reusable Django app for modelling provider/resource availability with weekly hours, breaks, one-off exceptions, and optional tenant-wide holidays. It answers “when can this provider be booked?” and stays out of booking/slot generation concerns.

Features

  • Weekly recurring working windows per provider
  • Recurring breaks inside working windows
  • Exceptions for closed days and special hours
  • Optional tenant holidays (enabled when a tenant model is configured)
  • Timezone-safe selectors that return aware datetimes
  • Admin UX tuned for day-of-week workflows

Installation

  1. Add the package and Django to your project (Django 4.2+):
pip install django-availability
  1. Configure settings:
  • AVAILABILITY_PROVIDER_MODEL (required): the provider model as app_label.ModelName (default: "providers.Provider").
  • AVAILABILITY_TENANT_MODEL (optional): tenant model as app_label.ModelName. When set, tenant FKs are added to models and TenantHoliday is enabled.
  1. Add to INSTALLED_APPS:
INSTALLED_APPS = [
    # ...
    "availability",
]
  1. Run migrations:
python manage.py migrate

Models

  • WeeklyAvailability: recurring weekly working windows (weekday, start_time, end_time, is_active, sort_order).
  • AvailabilityBreak: recurring breaks per weekday that subtract from working windows.
  • AvailabilityException: one-off CLOSED or SPECIAL_HOURS per date; unique per provider+date.
  • TenantHoliday (tenant mode only): tenant-wide closed dates.

Validation rules:

  • end_time must be after start_time.
  • Active weekly windows/breaks cannot overlap for a provider+weekday.
  • SPECIAL_HOURS require start/end; CLOSED must not provide times.
  • Tenant consistency enforced when AVAILABILITY_TENANT_MODEL is set.

Public API (selectors)

Import from availability.selectors:

  • get_working_windows_for_date(provider, date, tz=None) -> list[(start_dt, end_dt)]
  • get_working_windows(provider, start_date, end_date, tz=None) -> dict[date, list[(start_dt, end_dt)]]
  • is_provider_available(provider, dt, tz=None) -> bool

Example:

from datetime import date, datetime
from django.utils import timezone
from availability.selectors import get_working_windows_for_date, is_provider_available

provider = ...
target_date = date(2024, 1, 1)
tz = timezone.get_current_timezone()

windows = get_working_windows_for_date(provider, target_date, tz=tz)
if is_provider_available(provider, datetime(2024, 1, 1, 10, 30), tz=tz):
    print("open")

The selectors:

  • honor CLOSED/SPECIAL_HOURS exceptions
  • subtract breaks from weekly or special-hour windows
  • close days that fall on tenant holidays (if enabled)
  • return timezone-aware datetimes; tz defaults to Django’s current timezone

Admin

Admin list filters cover weekday/kind/tenant and call full_clean() on save for safety. Ordering is optimized for weekday flows.

Testing locally

This repo ships a minimal test project. Run:

python test availability

The helper script pins DJANGO_SETTINGS_MODULE=tests.settings so the bundled test provider/tenant models are used. You can pass other labels, e.g. python test tests.

Releasing to PyPI

  1. Bump version: update pyproject.toml (and availability/__init__.py if mirroring).
  2. Clean dist: remove old artifacts: rm -rf dist/ build/ *.egg-info.
  3. Build:
python -m pip install --upgrade build twine
python -m build
  1. Check: python -m twine check dist/*.
  2. Publish (replace token): python -m twine upload dist/* -u __token__ -p pypi-XXXXXXXXXXXXXXXXXXXX.
    • For TestPyPI: python -m twine upload --repository testpypi dist/*.
  3. Verify install (optional): pip install --no-cache-dir django-availability.

Scope notes

  • No booking/slot generation/payment/notification logic.
  • Datetimes are expected/stored in UTC; local rules are weekday + local times.
  • Overnight windows are not supported in v0.

Metadata

Release files for django-availability 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-availability 0.1.0
File Size Uploaded Provenance Actions
django_availability-0.1.0.tar.gz 12.6 kB Without provenance Details for django_availability-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-availability 0.1.0
File Interpreter ABI Platform Actions
django_availability-0.1.0-py3-none-any.whl Python 3 none any Details for django_availability-0.1.0-py3-none-any.whl

Total release size: 24.0 kB

Release files / django_availability-0.1.0.tar.gz

Download URL django_availability-0.1.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bf75ca825a8de10dd8cf391e421be462911f115bb95b3b4ff54fcfdd8868c05b
BLAKE2b-256 checksum
How to use checksums
b3c37c104f85bea7332fcc7591362e29a4b96b2baad9e6c12a4a50f2d49201e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / django_availability-0.1.0-py3-none-any.whl

Download URL django_availability-0.1.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bdf0a476b5a441e42fbf42859f621f4f1fab040a776c8cef6fe785a5839400d
BLAKE2b-256 checksum
How to use checksums
db22e02da355b22413274cbcc5eaa1c23ee9022d93fede7c60212a774cc31260
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Security for django-availability 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page