Skip to content

nvd_client.utils

Helpers for CVE ids and NVD timestamps. They are not re-exported from nvd_client. NvdApi calls them before it sends a request.

Parameter checks and NVD timestamp formatting.

NVD date parameters use extended ISO-8601 with milliseconds (YYYY-MM-DDTHH:MM:SS.sss) and an optional UTC offset. A positive offset must be sent as %2B rather than a raw +. This module formats the timestamp; requests percent-encodes it when the value is passed as a query parameter.

Functions:

Attributes:

MAX_DATE_RANGE module-attribute

MAX_DATE_RANGE = timedelta(days=120)

format_nvd_datetime

format_nvd_datetime(value: datetime) -> str

Format value as an NVD timestamp in UTC.

Naive values are treated as UTC. Aware values, including those built with zoneinfo, are converted to UTC. The +00:00 suffix is intentional: callers must not paste it into a URL by hand.

validate_and_convert_dates

validate_and_convert_dates(start_date: datetime | None, end_date: datetime | None, param_names: list[str]) -> tuple[str | None, str | None]

Validate a date pair and return NVD timestamp strings.

Both ends are required when either one is set. The span cannot exceed 120 days, which is NVD's maximum for every date-range parameter.

validate_cve_id

validate_cve_id(cve_id: str) -> bool

Return True when cve_id matches CVE-YYYY-NNNN.

Raises InvalidCVEIDError otherwise.