{"id":21107,"library":"datetype","title":"DateType","description":"A type wrapper for the standard library `datetime` that supplies stricter checks, such as making `datetime` not substitutable for `date`, and separating out Naive and Aware datetimes into separate, mutually-incompatible types. Current version: 2025.11.30. Released roughly monthly.","status":"active","version":"2025.11.30","language":"python","source_language":"en","source_url":"https://github.com/glyph/DateType","tags":["datetime","type-safety","stricter-types","python"],"install":[{"cmd":"pip install datetype","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Used for type hints like Literal on older Python versions","package":"typing-extensions","optional":true}],"imports":[{"note":"datetype.Date is not the same as datetime.date; they are incompatible by design.","wrong":"from datetime import date (DateType wraps but is incompatible)","symbol":"Date","correct":"from datetype import Date"},{"note":"datetype.DateTime is not substitutable for datetime.datetime.","wrong":"from datetime import datetime","symbol":"DateTime","correct":"from datetype import DateTime"},{"note":"DateTime requires aware (tz-aware) instances; use NaiveDateTime for naive.","wrong":"from datetype import DateTime (NaiveDateTime is distinct from DateTime)","symbol":"NaiveDateTime","correct":"from datetype import NaiveDateTime"},{"note":"AwareDateTime is an alias for DateTime; both require tz-aware.","wrong":"from datetype import DateTime","symbol":"AwareDateTime","correct":"from datetype import AwareDateTime"}],"quickstart":{"code":"from datetype import Date, DateTime, NaiveDateTime, AwareDateTime\nfrom datetime import timezone, timedelta\n\n# Date: no time, no timezone\nd = Date(2024, 12, 25)\nprint(d)  # 2024-12-25\n\n# NaiveDateTime: no timezone\nndt = NaiveDateTime(2024, 12, 25, 10, 30)\nprint(ndt)  # 2024-12-25 10:30:00\n\n# AwareDateTime: requires tzinfo\ntz = timezone(timedelta(hours=5))\nadt = AwareDateTime(2024, 12, 25, 10, 30, tzinfo=tz)\nprint(adt)  # 2024-12-25 10:30:00+05:00\n\n# Note: DateTime is same as AwareDateTime\nfrom datetype import DateTime as DT\nassert DT is AwareDateTime","lang":"python","description":"Create strict date and datetime objects that are not interchangeable with stdlib types."},"warnings":[{"fix":"Always use datetype types throughout your codebase, or convert using .to_stdlib() and .from_stdlib() methods.","message":"DateType types (Date, DateTime, etc.) are NOT interchangeable with stdlib datetime types. Passing a datetype.Date to a function expecting datetime.date will fail type checks and may raise errors at runtime if the function relies on datetime.date methods.","severity":"breaking","affected_versions":"all"},{"fix":"Use `NaiveDateTime` for naive datetimes and `AwareDateTime` (or `DateTime`) for aware datetimes.","message":"DateTime is an alias for AwareDateTime, not NaiveDateTime. A naive datetime (without tzinfo) will not be accepted as DateTime; you must use NaiveDateTime explicitly.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `Date`, `DateTime`, `NaiveDateTime`, `AwareDateTime` with capital first letter.","message":"The `date` and `datetime` names from `datetype` were previously exported but now prefer `Date` and `DateTime` (capitalized). The old lowercase aliases may be removed in future versions.","severity":"deprecated","affected_versions":">=2024.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Either make the datetime aware by adding a tzinfo, or use NaiveDateTime explicitly in the type annotation.","cause":"Trying to pass a NaiveDateTime where an AwareDateTime (or DateTime) is expected.","error":"TypeError: NaiveDateTime instance is not aware"},{"fix":"Use DateTime or NaiveDateTime if you need time components.","cause":"Date objects do not have time components. Attempted to access time attribute on a Date.","error":"AttributeError: 'Date' object has no attribute 'hour'"},{"fix":"Convert one type to the other using .to_stdlib() or .from_stdlib() before comparing.","cause":"Mixing stdlib and DateType types in comparisons.","error":"TypeError: cannot compare datetime.date with datetype.Date"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}