Skip to main content

Python library for Croatian public holidays with computed Easter/Corpus Christi, fixed dates, and optional web scraping.

Project description

Croatian Holidays

PyPI version Python versions License

A lightweight Python utility for Croatian public holidays: compute holidays for any year, check if today is a holiday, list upcoming holidays, and optionally scrape an external reference page.

  • Pure Python for computed holidays (Easter, Corpus Christi, + fixed dates)
  • Typed exceptions and no print spam (uses logging)
  • Optional web parsing with timeouts and structural checks
  • Pretty-print and JSON save helpers

Project name on PyPI is croatian-holidays, while the import name is croatianholidays. You can check it out on https://pypi.org/project/croatian-holidays/

Installation

pip install croatian-holidays

or

pip install croatian-holidays==0.1.2 ## For specific versions

Quick start

import datetime as dt
from croatianholidays import CroatianHolidays

ch = CroatianHolidays()

# 1) Is today a holiday?
print("Today is holiday:", ch.isHoliday())

# 2) All holidays for a year
hol_2025 = ch.getHolidays(2025)  # dict: "dd. mm. yyyy." -> "Holiday name"
print(hol_2025["01. 05. 2025."])  # "Praznik rada"

# 3) Include localized day-of-week and pretty output
print(ch.getHolidays(2025, showdays=True, prettyprint=True))

# 4) Upcoming holidays after now (current year)
print(ch.upcomingHolidays(date=dt.datetime.now(), showdays=True, prettyPrint=True))

# 5) Holidays between two dates (inclusive)
print(ch.getHolidaysBetweenDates("01. 05. 2025.", "31. 12. 2025.", showdays=True, prettyPrint=True))

# 6) Persist to JSON
data = ch.getHolidays(2025, showdays=True)
from croatian_holidays import SaveError
try:
    ch.saveToJson(data, "croatia_2025_holidays.json")
except SaveError as e:
    print("Saving failed:", e)

Features

  • Algorithmic dates: Easter (Meeus/Jones/Butcher), Corpus Christi (+60 days)
  • Fixed-date holidays: New Year’s, Statehood Day, All Saints’, etc.
  • Features:
    • getHolidays(year, showdays=False, prettyprint=False)
    • upcomingHolidays(date, showdays=False, prettyPrint=False)
    • getHolidaysBetweenDates(start_date, end_date, showdays=False, prettyPrint=False)
    • isHoliday()
    • getHolidaysFromWeb(base_url=..., prettyPrint=False, timeout=10.0, ...)
    • prettyPrint(dict)
    • saveToJson(dict, filename)
  • 🧯 Errors are explicit and do not leak prints, using logger
  • 🧰 Logging-friendly: ships with a NullHandler; opt-in to logs in your app.

Module Reference

Date strings use "dd. mm. yyyy." (note the trailing dot).

CroatianHolidays.getHolidays(year, showdays=False, prettyprint=False) -> dict | str

Return holidays for year.

  • showdays=True → values become { "name": ..., "day_of_week": ... } (Croatian weekday).
  • prettyprint=True → returns pretty JSON str instead of dict.

CroatianHolidays.upcomingHolidays(date, showdays=False, prettyPrint=False) -> dict | str

Return upcoming holidays after the given datetime (current year only).

CroatianHolidays.getHolidaysBetweenDates(start_date, end_date, showdays=False, prettyPrint=False, dateformat="%d. %m. %Y.") -> dict | str

Return holidays within an inclusive range. start_date/end_date can be str, date, or datetime.

CroatianHolidays.isHoliday() -> bool

True if today is a holiday.

CroatianHolidays.getHolidaysFromWeb(base_url=..., prettyPrint=False, timeout=10.0, session=None, user_agent=None) -> dict | str

Try to parse an external web page for holidays

CroatianHolidays.prettyPrint(json_data: dict) -> str

Pretty JSON with UTF-8 (no ASCII escapes).

CroatianHolidays.saveToJson(data: dict, filename: str, encoding="utf-8") -> None

Write a dictionary to a JSON file.

Exceptions

Import from the package root:

from croatian_holidays import (
    CroatianHolidaysError, InvalidYearError, DateFormatError,
    NetworkError, ParseError, SaveError
)
  • InvalidYearError: year must be 1583..4099 (Gregorian computus range).
  • DateFormatError: invalid date strings / formatting issues.
  • NetworkError: timeouts, connection issues, HTTP errors in web fetch.
  • ParseError: the web page did not match expected structure.
  • SaveError: file write errors.
  • CroatianHolidaysError: base class for all package errors.

Logging

By default, the library is quiet. To see warnings or debug messages:

import logging
logging.basicConfig(level=logging.INFO)

Development

git clone https://github.com/mgracanin/croatian-holidays.git
cd croatian-holidays
python -m venv .venv && source .venv/bin/activate  # or use whatever you like
pip install -e .

Recommended tooling (optional):

  • ruff for linting
  • mypy for typing
  • pytest for tests

Versioning & Compatibility

  • Python 3.8+
  • Semantic-ish versioning; breaking API changes bump the minor/major.

License

MIT — 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

croatian_holidays-0.1.3.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

croatian_holidays-0.1.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file croatian_holidays-0.1.3.tar.gz.

File metadata

  • Download URL: croatian_holidays-0.1.3.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for croatian_holidays-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3e3b9c955b1313cddf9e514c5eb11ff5f95e18159b43a1f2cbc8440d230260af
MD5 466dfc6f50cb6b9c2e2d54b9f7d9d4d7
BLAKE2b-256 c997f6a6a69d36a67d564478fa41adf75955abf0f5bbbb6a92d3da5d661838b3

See more details on using hashes here.

File details

Details for the file croatian_holidays-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for croatian_holidays-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2dad3cc7927a01b6d0e7a6574ac8a9b15d7c5492956b8f653e138003bec85042
MD5 196fcc926880dff18186d65debed4b63
BLAKE2b-256 4d5ea261924878f15e52dee41b53fd9f2cdc4c8fb0f7f9a9e473cd2f58172820

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