Skip to content

Common

pyqwest.Headers

Container of HTTP headers.

This class behaves like a dictionary with case-insensitive keys and string values. Standard dictionary access will act as if keys can only have a single value. The add method can be used to It additionally can be used to store multiple values for the same key by using the add method. Iterating over values or items will return all values, including duplicates.

Parameters:

Name Type Description Default
items Mapping[str | HTTPHeaderName, str] | Iterable[tuple[str | HTTPHeaderName, str]] | None

Initial headers to add.

None

__getitem__

Return the header value for the key.

If multiple values are present for the key, returns the first value.

Parameters:

Name Type Description Default
key str | HTTPHeaderName

The header name.

required

Raises:

Type Description
KeyError

If the key is not present.

__setitem__

Sets the header value for the key, replacing any existing values.

Parameters:

Name Type Description Default
key str | HTTPHeaderName

The header name.

required
value str

The header value.

required

__delitem__

Deletes all values for the key.

Parameters:

Name Type Description Default
key str | HTTPHeaderName

The header name.

required

Raises:

Type Description
KeyError

If the key is not present.

__iter__

Returns an iterator over the header names.

__len__

Returns the number of unique header names.

__eq__

Compares the headers for equality with another Headers object, mapping, or iterable of key-value pairs.

Parameters:

Name Type Description Default
other object

The object to compare against.

required

get

Returns the header value for the key, or default if not present.

Parameters:

Name Type Description Default
key str | HTTPHeaderName

The header name.

required
default _T

The default value to return if the key is not present.

None

popitem

Removes and returns an arbitrary (name, value) pair. Will return the same name multiple times if it has multiple values.

Raises:

Type Description
KeyError

If the headers are empty.

setdefault

If the key is not present, sets it to the default value. Returns the value for the key.

Parameters:

Name Type Description Default
key str | HTTPHeaderName

The header name.

required
default str | None

The default value to set and return if the key is not present.

None

add

Adds a header value for the key. Existing values are preserved.

Parameters:

Name Type Description Default
key str | HTTPHeaderName

The header name.

required
value str

The header value.

required

clear

Removes all headers.

getall

Returns all header values for the key.

Parameters:

Name Type Description Default
key str | HTTPHeaderName

The header name.

required

items

Returns a new view of all header name-value pairs, including duplicates.

keys

Returns a new view of all unique header names.

values

Returns a new view of all header values, including duplicates.

__contains__

Returns True if the header name is present.

Parameters:

Name Type Description Default
key object

The header name.

required

pyqwest.HTTPHeaderName

An enum type corresponding to HTTP header names.

Parameters:

Name Type Description Default
name str

The header name.

required

ACCEPT instance-attribute

The "accept" header.

ACCEPT_CHARSET instance-attribute

The "accept-charset" header.

ACCEPT_ENCODING instance-attribute

The "accept-encoding" header.

ACCEPT_LANGUAGE instance-attribute

The "accept-language" header.

ACCEPT_RANGES instance-attribute

The "accept-ranges" header.

ACCESS_CONTROL_ALLOW_CREDENTIALS instance-attribute

The "access-control-allow-credentials" header.

ACCESS_CONTROL_ALLOW_HEADERS instance-attribute

The "access-control-allow-headers" header.

ACCESS_CONTROL_ALLOW_METHODS instance-attribute

The "access-control-allow-methods" header.

ACCESS_CONTROL_ALLOW_ORIGIN instance-attribute

The "access-control-allow-origin" header.

ACCESS_CONTROL_EXPOSE_HEADERS instance-attribute

The "access-control-expose-headers" header.

ACCESS_CONTROL_MAX_AGE instance-attribute

The "access-control-max-age" header.

ACCESS_CONTROL_REQUEST_HEADERS instance-attribute

The "access-control-request-headers" header.

ACCESS_CONTROL_REQUEST_METHOD instance-attribute

The "access-control-request-method" header.

AGE instance-attribute

The "age" header.

ALLOW instance-attribute

The "allow" header.

ALT_SVC instance-attribute

The "alt-svc" header.

AUTHORIZATION instance-attribute

The "authorization" header.

CACHE_CONTROL instance-attribute

The "cache-control" header.

CACHE_STATUS instance-attribute

The "cache-status" header.

CDN_CACHE_CONTROL instance-attribute

The "cdn-cache-control" header.

CONNECTION instance-attribute

The "connection" header.

CONTENT_DISPOSITION instance-attribute

The "content-disposition" header.

CONTENT_ENCODING instance-attribute

The "content-encoding" header.

CONTENT_LANGUAGE instance-attribute

The "content-language" header.

CONTENT_LENGTH instance-attribute

The "content-length" header.

CONTENT_LOCATION instance-attribute

The "content-location" header.

CONTENT_RANGE instance-attribute

The "content-range" header.

CONTENT_SECURITY_POLICY instance-attribute

The "content-security-policy" header.

CONTENT_SECURITY_POLICY_REPORT_ONLY instance-attribute

The "content-security-policy-report-only" header.

CONTENT_TYPE instance-attribute

The "content-type" header.

COOKIE instance-attribute

The "cookie" header.

DNT instance-attribute

The "dnt" header.

DATE instance-attribute

The "date" header.

ETAG instance-attribute

The "etag" header.

EXPECT instance-attribute

The "expect" header.

EXPIRES instance-attribute

The "expires" header.

FORWARDED instance-attribute

The "forwarded" header.

FROM instance-attribute

The "from" header.

HOST instance-attribute

The "host" header.

IF_MATCH instance-attribute

The "if-match" header.

IF_MODIFIED_SINCE instance-attribute

The "if-modified-since" header.

IF_NONE_MATCH instance-attribute

The "if-none-match" header.

IF_RANGE instance-attribute

The "if-range" header.

IF_UNMODIFIED_SINCE instance-attribute

The "if-unmodified-since" header.

LAST_MODIFIED instance-attribute

The "last-modified" header.

The "link" header.

LOCATION instance-attribute

The "location" header.

MAX_FORWARDS instance-attribute

The "max-forwards" header.

ORIGIN instance-attribute

The "origin" header.

PRAGMA instance-attribute

The "pragma" header.

PROXY_AUTHENTICATE instance-attribute

The "proxy-authenticate" header.

PROXY_AUTHORIZATION instance-attribute

The "proxy-authorization" header.

PUBLIC_KEY_PINS instance-attribute

The "public-key-pins" header.

PUBLIC_KEY_PINS_REPORT_ONLY instance-attribute

The "public-key-pins-report-only" header.

RANGE instance-attribute

The "range" header.

REFERER instance-attribute

The "referer" header.

REFERRER_POLICY instance-attribute

The "referrer-policy" header.

REFRESH instance-attribute

The "refresh" header.

RETRY_AFTER instance-attribute

The "retry-after" header.

SEC_WEBSOCKET_ACCEPT instance-attribute

The "sec-websocket-accept" header.

SEC_WEBSOCKET_EXTENSIONS instance-attribute

The "sec-websocket-extensions" header.

SEC_WEBSOCKET_KEY instance-attribute

The "sec-websocket-key" header.

SEC_WEBSOCKET_PROTOCOL instance-attribute

The "sec-websocket-protocol" header.

SEC_WEBSOCKET_VERSION instance-attribute

The "sec-websocket-version" header.

SERVER instance-attribute

The "server" header.

The "set-cookie" header.

STRICT_TRANSPORT_SECURITY instance-attribute

The "strict-transport-security" header.

TE instance-attribute

The "te" header.

TRAILER instance-attribute

The "trailer" header.

TRANSFER_ENCODING instance-attribute

The "transfer-encoding" header.

USER_AGENT instance-attribute

The "user-agent" header.

UPGRADE instance-attribute

The "upgrade" header.

UPGRADE_INSECURE_REQUESTS instance-attribute

The "upgrade-insecure-requests" header.

VARY instance-attribute

The "vary" header.

VIA instance-attribute

The "via" header.

WARNING instance-attribute

The "warning" header.

WWW_AUTHENTICATE instance-attribute

The "www-authenticate" header.

X_CONTENT_TYPE_OPTIONS instance-attribute

The "x-content-type-options" header.

X_DNS_PREFETCH_CONTROL instance-attribute

The "x-dns-prefetch-control" header.

X_FRAME_OPTIONS instance-attribute

The "x-frame-options" header.

X_XSS_PROTECTION instance-attribute

The "x-xss-protection" header.

pyqwest.HTTPVersion

An enumeration of HTTP versions.

HTTP1 instance-attribute

HTTP/1.1

HTTP2 instance-attribute

HTTP/2

HTTP3 instance-attribute

HTTP/3