GitHub

API reference for schema.

Schemas of the HTTP values (Effect's Schema.Headers, Cookie, Cookies, RecordFromCookies, UrlParams, JsonFromUrlParamsField, RecordFromUrlParams, RetryAfter, RetryAfterFromString and DateTimeUtcFromHttpDate). They live here, not in pyfect.schema, because pyfect.http is built on pyfect.schema::

from pyfect.http import schema as HS

S.decode_unknown_sync(HS.RecordFromCookies)(cookies)  # {"session": "abc"}

RetryAfter is a declaration of headers.RetryAfterDuration / RetryAfterDateTime (Effect's is a union of tagged structs of the same shape): the duration must be finite and non-negative.

Values

AttributeTypeDescription
HeadersBottom[_headers.Headers]

pyfect.http.headers.Headers, written as a {name: value} record.

CookieBottom[_cookies.Cookie]

A pyfect.http.cookies.Cookie.

CookiesBottom[_cookies.Cookies]

pyfect.http.cookies.Cookies, written in JSON as its Set-Cookie headers.

RecordFromCookiesDecodeToSchema[dict[str, str], _cookies.Cookies]

The cookies' values by name; encoding makes plain cookies.

UrlParamsBottom[_url_params.UrlParams]

pyfect.http.url_params.UrlParams, written as its (key, value) pairs (a redacted value as its text).

RecordFromUrlParamsDecodeToSchema[dict[str, str | tuple[str, ...]], _url_params.UrlParams]

The params by key: one value, or a tuple of a repeated key's values.

RetryAfterBottom[_headers.RetryAfter]

A parsed Retry-After: a finite, non-negative delay or a date.

RetryAfterFromStringDecodeToSchema[_headers.RetryAfter, str]

A Retry-After header value: whole seconds or an HTTP date.

DateTimeUtcFromHttpDateDecodeToSchema[datetime, str]

A UTC datetime from any HTTP date format (RFC 9110 ยง5.6.7), written back as an IMF-fixdate.

Functions

JsonFromUrlParamsField

JsonFromUrlParamsField(field) -> DecodeToSchema[object, _url_params.UrlParams]

The JSON text of the params' first field value, parsed (missing: a MissingKey at field). Effect's reviver option is not ported, as for S.from_json_string.

ParameterTypeDescription
fieldstr

Returns DecodeToSchema[object, _url_params.UrlParams]

def JsonFromUrlParamsField(field: str, /) -> DecodeToSchema[object, _url_params.UrlParams]:
    """The JSON text of the params' first ``field`` value, parsed (missing:
    a ``MissingKey`` at ``field``). Effect's ``reviver`` option is not
    ported, as for ``S.from_json_string``."""

    def decode(params: _url_params.UrlParams, _: ParseOptions) -> Exit[str, Issue]:
        value = params.get_first(field)
        if value is None:
            return fail_exit(Pointer((field,), MissingKey()))
        return Success(value)

    def encode(value: str, _: ParseOptions) -> Exit[_url_params.UrlParams, Issue]:
        return Success(_url_params.make([(field, value)]))

    json = from_json_string(Unknown)
    return UrlParams.pipe(decode_to(json, T.transform_effect(decode=decode, encode=encode)))