Skip to main content

Generate bookable slot candidates for appointment booking systems.

Project description

django-slots

Reusable Django app for generating bookable slot candidates for appointment booking systems. Given a service and provider, it returns slot start/end times within working windows while respecting buffers, minimum notice, and maximum advance rules.

What it does

  • Slices provider working windows into discrete slots using service rules.
  • Supports optional addons that extend duration.
  • Respects buffers, minimum notice, maximum advance, and fixed start intervals.
  • Provides hooks for custom working window and busy interval providers.

What it does not do

  • Does not create or store bookings.
  • Does not process payments or send notifications.
  • Does not persist slots by default (pure computation only).

Compatibility

  • Django 4.2+ (works on Django 5.x).
  • Python 3.10+.
  • Timezone-aware; expects aware datetimes (UTC internally, align to local rules via tz argument).
  • Works on SQLite for tests; production-friendly with PostgreSQL.

Settings

SLOTS_TENANT_MODEL = None  # e.g. "tenants.Tenant" (optional)
SLOTS_SERVICE_MODEL = "services.Service"
SLOTS_PROVIDER_MODEL = "providers.Provider"
SLOTS_GET_WORKING_WINDOWS_FUNC = "availability.logic.get_working_windows"
SLOTS_GET_BUSY_INTERVALS_FUNC = None  # e.g. "bookings.selectors.get_busy_intervals"
SLOTS_DEFAULT_INTERVAL_MINUTES = 15
SLOTS_MAX_SLOTS_PER_DAY = 500

Provide callable paths as strings; functions are imported lazily. Override these in your Django settings.

Integration points

  • Working windows: By default imports availability.logic.get_working_windows from django-availability if installed. Override SLOTS_GET_WORKING_WINDOWS_FUNC to supply your own callable. The callable should return a list of (start_dt, end_dt) windows for a given provider and date.
  • Busy intervals: Set SLOTS_GET_BUSY_INTERVALS_FUNC to a callable that returns intervals to exclude (e.g., existing bookings).
  • Service / Provider / Tenant models: Set model paths via settings if you use custom apps.

Public API

  • slots.engine.generate_slots(service, provider, start_date, end_date, *, tz=None, now_dt=None, addons=None, tenant=None) -> dict[date, list[Slot]]
  • slots.selectors.list_available_slots(...) for a single provider.
  • slots.selectors.list_available_slots_for_service(...) to fan out across providers (requires the providers app; otherwise raises a helpful error).

Slots are returned as lightweight dataclass instances with start, end, provider_id, service_id, capacity_total, capacity_remaining, and meta.

Running tests

python test django-slot

The runner defaults DJANGO_SETTINGS_MODULE to slots.tests.settings for local testing.

Publish to PyPI

set PYPI_TOKEN=your-token
python upload project

The upload helper installs build tooling, builds the package, and uploads via Twine using __token__ authentication.

Custom working windows example

def my_working_windows(provider, date, tz=None, tenant=None, **kwargs):
    # Return aware datetimes in the provider's timezone
    start = tz.localize(datetime.datetime.combine(date, datetime.time(9, 0)))
    end = tz.localize(datetime.datetime.combine(date, datetime.time(17, 0)))
    return [(start, end)]

# settings.py
SLOTS_GET_WORKING_WINDOWS_FUNC = "path.to.my_working_windows"

Licence

MIT Licence. See LICENSE.

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

mroudai_django_slots-0.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

mroudai_django_slots-0.1.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mroudai_django_slots-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2eb49e76d2340e3b8f0c6fabbff5340742fb091599831ad4e4a67d7ed8129f2b
MD5 fa937e9006a6e5d25073aa21a0839faa
BLAKE2b-256 dab96e7dbe0d9397ced6652b40e20a5e6279ce713712e2df4d5f27022096f2f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mroudai_django_slots-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84e97c157af9497400823abfb406d2184dae815946dc74462c0d834aac89eb06
MD5 d82a4f070baf084293c001ffa827abff
BLAKE2b-256 d65d35782e369e22f99b974cee42f8662b0a51232afa7f8fb17b37ab5d791060

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