Skip to main content

KTcalendars

Test Lint Documentation Pypi codecov security: bandit

KTCalendars is a library providing utility classes for country-specific holiday-aware calendars and dates.

It builds on the holidays package and provides:

  • KTDay — a rich day object with date parsing, arithmetic, comparisons and holiday/work-day checks.
  • KTCalendar — a calendar.Calendar subclass bound to a country calendar, with configurable weekend days and work-day and week iteration helpers.
  • AbstractConfiguration — a pluggable configuration class centralising holiday overrides (e.g. company closures) and the default country calendar code.
  • KTDateRange — a psycopg DateRange subclass with PostgreSQL-canonical [) bounds, KTDay iteration and rich comparison, containment and intersection helpers (requires the psycopg extra).
from ktcalendars import KTCalendar

cal = KTCalendar(country_code="IT")
day = cal.get_ktday("2025-06-02")  # Festa della Repubblica
day.is_holiday                     # True
day.is_workday                     # False
cal.get_work_days("2025-06-01", "2025-06-08")
# [K2025-06-03, K2025-06-04, K2025-06-05, K2025-06-06]

Day parsing, arithmetic and comparisons

from ktcalendars import KTDay

day = KTDay("2025-06-02")   # also "2025/06/02", "20250602", a date, a KTDay or None (today)
day.day_of_week             # 'Monday'
day + 7                     # K2025-06-09
day - KTDay("2025-05-31")   # 2 (days)
day == "2025-06-02"         # True
list(KTDay("2025-06-01").range_to("2025-06-03"))
# [K2025-06-01, K2025-06-02, K2025-06-03]

Weekend days per country

KTCalendar(country_code="EG").weekend_days   # (4, 5) — Friday and Saturday
KTCalendar(country_code="IT").weekend_days   # (5, 6) — Saturday and Sunday

cal = KTCalendar(country_code="IT", weekends=(6,))  # Sunday-only weekend
cal.get_ktday("2025-06-07").is_weekend       # False (a Saturday)

Week and month iteration

cal = KTCalendar(country_code="IT")
cal.week_for("2025-06-04")           # (K2025-06-02, K2025-06-08)
list(cal.iter_week("2025-06-04"))    # the seven days of that week
list(cal.month_weeks_days(2025, 6))  # complete weeks covering June 2025

Date ranges

KTDateRange (requires the psycopg extra) stores date ranges in the PostgreSQL canonical form — lower bound included, upper bound excluded:

from ktcalendars.ranges import KTDateRange

r = KTDateRange("2025-06-01", "2025-06-04")           # upper bound excluded
list(r)                                               # [K2025-06-01, K2025-06-02, K2025-06-03]
KTDateRange.from_start_end("2025-06-01", "2025-06-03")  # both bounds included, same range

"2025-06-03" in r                                     # True
r.overlap(KTDateRange("2025-06-03", "2025-06-10"))    # True
r.intersection(("2025-06-03", "2025-06-10"))          # [2025-06-03:2025-06-04)
r.precedes("2025-06-04")                              # True — adjacent, just before that day

Company-specific holidays

Point the KTCALENDAR_CONFIG environment variable to a subclass of AbstractConfiguration to add your own holidays on top of the official country calendars:

import datetime

from ktcalendars import AbstractConfiguration


class CompanyConfiguration(AbstractConfiguration):
    def get_holiday_overrides(self, country_calendar_code, from_date=None, to_date=None):
        return {datetime.date(2025, 12, 24): "Christmas Eve closure"}
export KTCALENDAR_CONFIG=mypackage.config.CompanyConfiguration

See the documentation for configuration and usage, and the changelog for notable changes between releases.

Requirements

  • Python 3.10 or later

Installation

Install ktcalendars using your package manager of choice, e.g. Pip:

pip install ktcalendars

To use KTDateRange, install the psycopg extra:

pip install ktcalendars[psycopg]

Bug reports and requests for enhancements

Please open an issue on the project's issue tracker on GitHub.

Contributing to the project

See the contribution guide.

Licensing

Licensed under the Apache License 2.0.

Metadata

Release files for ktcalendars 3.1.1

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

Source distribution (sdist)

Source distribution for ktcalendars 3.1.1
File Size Uploaded Provenance
ktcalendars-3.1.1.tar.gz 13.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ktcalendars 3.1.1
File Interpreter ABI Platform
ktcalendars-3.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.6 kB

Release files / ktcalendars-3.1.1.tar.gz

Download URL ktcalendars-3.1.1.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
64c73ba0bcd6d8e993b09ccb04ac91caf7009df4d3937f5194a36f77cfb266c0
BLAKE2b-256 checksum
How to use checksums
d8512be1639e9299eb8fc10cc331d6c332cd4bd212c4db607409743320a88ff0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / ktcalendars-3.1.1-py3-none-any.whl

Download URL ktcalendars-3.1.1-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ddfc23bee2162bdd874b78b4b9443c60a8393d52540b1f7fea60e766523cc91
BLAKE2b-256 checksum
How to use checksums
85276d6e7708cbe45699ae993bf8f7e49193c0f27306d552cc5aedddca939680
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for ktcalendars 3.1.1

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.

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