Skip to main content

Japanese holiday detection library based on Cabinet Office data, ported from holiday-jp-npm.

Project description

holiday-jp-pip

PyPI Python Versions test License: MIT

内閣府ホームページの「国民の祝日」についてに基づいて平日や祝日を判定する Python ライブラリです。 独自の祝日を追加することも可能です。

JS 版 @sway11466/holiday-jp-npm の Python 移植版です。

  • 判定ルール

    日付の種類 判定方法
    平日 週末でも祝日でもない日
    週末 土曜日および日曜日(対象となる曜日は設定で変更可能)
    祝日 内閣府ホームページの「国民の祝日」についてに記載の祝日
  • 判定の例(2024年5月)

    日付の種類 5/1(水) 5/2(木) 5/3(金) 5/4(土) 5/5(日) 5/6(月) 5/7(火)
    平日 × × × ×
    週末 × × × × ×
    祝日 × × ×

インストール

pip install holiday-jp-pip

使い方

  • 初期化

    from holiday_jp import HolidayJP
    holidayjp = HolidayJP()
    
  • 指定日が祝日であるか判定する

    from datetime import date
    ret = holidayjp.is_holiday(date(2021, 5, 3))  # 2021/5/3 憲法記念日
    print(ret)  # True
    
  • 指定日が平日であるか判定する

    ret = holidayjp.is_weekday(date(2021, 5, 7))  # 2021/5/7 平日
    print(ret)  # True
    
  • 指定した条件に当てはまる祝日を取得する(例 1)

    holidays = holidayjp.get(year=2021, month=5)
    print(len(holidays))           # 3
    print(holidays[0].name)        # 憲法記念日
    print(holidays[0].local_date)  # 2021-05-03 00:00:00+09:00 (JST 0:00 の datetime)
    
  • 指定した条件に当てはまる祝日を取得する(例 2)

    holidays = holidayjp.get(year=2021, name="スポーツの日")
    print(len(holidays))                              # 1
    print(holidays[0].local_date)                     # 2021-07-23 00:00:00+09:00
    print(holidays[0].local_date.astimezone().date()) # 実行環境 TZ で見た日付
    
  • 独自の祝日を追加する

    from datetime import date, datetime
    from holiday_jp import HolidayJP, Holiday, JST
    
    additional = [Holiday(year=2023, month=3, date=10, name="test",
                          local_date=datetime(2023, 3, 10, tzinfo=JST))]
    holidayjp = HolidayJP(extends=additional)
    ret = holidayjp.is_holiday(date(2023, 3, 10))
    print(ret)  # True
    

説明

  • 1955 年〜2027 年に対応しています
    • 内閣府ホームページで公開しているデータに依存しているためです
    • 対応外の日付を指定するとエラーを起こします(設定で変更可能)
  • このライブラリは実行環境のタイムゾーンを考慮して日本時間での祝日判定を行います
  • 設定で以下の挙動を変更可能です
    • 対応外の日付を指定した場合のエラー発生有無
    • タイムゾーン考慮の有無
    • 週末として扱う曜日
    • 独自の祝日の追加
  • より詳細な情報は doc フォルダ 内のドキュメントを参照してください

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

holiday_jp_pip-0.2.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

holiday_jp_pip-0.2.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file holiday_jp_pip-0.2.0.tar.gz.

File metadata

  • Download URL: holiday_jp_pip-0.2.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.9 {"installer":{"name":"uv","version":"0.11.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for holiday_jp_pip-0.2.0.tar.gz
Algorithm Hash digest
SHA256 12b5bc86e48a477f1173a22e9557f5f88fd9644b9d5700e812670c70397dcbe7
MD5 1e03d4268b271d5f63f70e6fa10570dc
BLAKE2b-256 ca5f03ede64203da68ec7032f3350bf2344a40a2b7673f5701398757c71bd5be

See more details on using hashes here.

File details

Details for the file holiday_jp_pip-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: holiday_jp_pip-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.9 {"installer":{"name":"uv","version":"0.11.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for holiday_jp_pip-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e1e5b8c74520897d6713cfc4028e930cb9d47c0fb69a27cbf8e1817147cb6d1
MD5 c6ba9aa789825401d3044947690880fc
BLAKE2b-256 e0f7d1544d881e0d8787de1dd67fc8ab73916627e33ce7144328449176b57daf

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