Typing Stubs for pyRFC3339
types-pyrfc3339 provides high-quality static type annotations (typing stubs) for the pyRFC3339 library. pyRFC3339 itself is a Python library that parses and generates RFC 3339-compliant timestamps using Python's `datetime.datetime` objects. This stub package, currently at version 2.0.1.20250825, is automatically generated and released from the community-driven Typeshed repository, typically with daily updates to keep pace with changes in the runtime library.
Common errors
-
ModuleNotFoundError: No module named 'pyrfc3339'
cause The `pyRFC3339` runtime library is not installed, even though `types-pyrfc3339` might be.fixRun `pip install pyrfc3339` to install the actual library that provides the functions. -
mypy: Argument 1 to "generate" has incompatible type "str"; expected "datetime.datetime"
cause You are passing an incorrect type (e.g., `str`) to a function that expects a `datetime.datetime` object, as enforced by the `types-pyrfc3339` stubs.fixEnsure the arguments passed to `pyrfc3339.generate` and `pyrfc3339.parse` match the expected types (e.g., `datetime.datetime` for `generate`, `str` for `parse`).
Warnings
- gotcha Installing `types-pyrfc3339` does not install the `pyRFC3339` runtime library itself. You must install `pyRFC3339` separately for your code to execute. `types-pyrfc3339` only provides type information.
- gotcha Version mismatches between `types-pyrfc3339` and `pyRFC3339` can lead to inaccurate type checking. Typeshed stubs are frequently updated, sometimes daily, and may reflect newer versions of the runtime library.
- gotcha Do not attempt to import symbols directly from `types_pyrfc3339`. The stub package's name on PyPI (`types-pyrfc3339`) is for installation purposes only. Runtime imports should always be from the actual library: `from pyrfc3339 import ...`.
Install
-
pip install types-pyrfc3339
Imports
- generate
from types_pyrfc3339 import generate
from pyrfc3339 import generate
- parse
from types_pyrfc3339 import parse
from pyrfc3339 import parse
Quickstart
import datetime
from pyrfc3339 import generate, parse
# Get current UTC time to generate an RFC 3339 timestamp
now_utc = datetime.datetime.now(datetime.timezone.utc)
print(f"Current UTC datetime: {now_utc.isoformat()}")
# Generate RFC 3339 timestamp string
rfc3339_string = generate(now_utc)
print(f"Generated RFC 3339 string: {rfc3339_string}")
# Parse an RFC 3339 timestamp string back to a datetime object
some_rfc3339_string = "2023-10-27T10:30:00.123456Z"
parsed_dt = parse(some_rfc3339_string)
print(f"Parsed RFC 3339 string: {parsed_dt}")
# The presence of types-pyrfc3339 allows type checkers (e.g., Mypy) to validate arguments:
# For example, uncommenting the line below would trigger a type error:
# generate("not a datetime object")