Typing stubs for croniter
types-croniter is a type stub package from the `typeshed` project, providing external type annotations for the `croniter` library. It enables static analysis tools like MyPy and Pyright to perform type checking on code that uses `croniter`, improving code quality and catching potential type-related errors before runtime. The current version, 6.2.2.20260402, is designed to provide accurate annotations for `croniter==6.2.2`. These packages are part of the `typeshed` project and are released frequently, often daily, through `typeshed`'s automated processes.
Warnings
- gotcha Version mismatches between `types-croniter` and the `croniter` runtime library can lead to incorrect or incomplete type checking results. The `types-croniter` version typically reflects the `croniter` version it targets (e.g., `types-croniter==6.2.2.YYYYMMDD` targets `croniter==6.2.2`).
- breaking `types-croniter` is a stub-only package and does not include the actual `croniter` runtime code. Installing `types-croniter` alone will not provide the `croniter` functionality.
- gotcha For MyPy versions 0.900 and later, third-party stub packages like `types-croniter` must be explicitly installed. They are no longer bundled with MyPy. Failing to install them will result in 'Missing imports' or 'Library stubs not installed' errors.
- gotcha While `typeshed` aims to minimize breaking changes, updates to stub packages can sometimes introduce changes that cause type checking to fail, even if the underlying runtime library has not changed. This is due to evolving type system features or more precise annotations.
Install
-
pip install types-croniter
Imports
- croniter
from croniter import croniter
Quickstart
from datetime import datetime
from croniter import croniter
# types-croniter provides static type checking for the 'croniter' library.
# Install it (pip install types-croniter) to enable your type checker (e.g., MyPy)
# to validate the usage of croniter objects and methods.
def schedule_info(cron_expression: str, start_from: datetime) -> None:
"""
Calculates and prints the next two scheduled times based on a cron expression.
Type hints here are validated by types-croniter if installed.
"""
cron_iterator: croniter = croniter(cron_expression, start_from)
print(f"Cron expression: '{cron_expression}'")
print(f"Starting from: {start_from}")
print(f"Next occurrence: {cron_iterator.get_next(datetime)}")
print(f"Second next occurrence: {cron_iterator.get_next(datetime)}")
if __name__ == "__main__":
current_time = datetime(2026, 4, 6, 10, 30)
schedule_info('0 0 * * *', current_time) # Daily at midnight
print("-" * 20)
schedule_info('*/15 * * * *', current_time) # Every 15 minutes