Skip to main content

A library of classes for HAR data using pyserde.

Project description

A library of classes for HAR data using pyserde.

The library is focused on providing a complete F-Algebra for HAR data and associated morphisms but also contains canonical types for basic usages.

F-Algebra classes

There is one generic-ish class for every HAR type and are prefixed with F. All nested HAR data has been replaced with type parameters. Some types have no nested HAR data and so have no generic parameters but are included for completeness. All types can be imported from harf_serde.harf or directly from harf_serde.

There is one edge case for post data. Since some of the parameters defined in the spec are mutually exclusive there are two classes for post data. PostDataParamF for ParamF based post data, and PostDataTextF for text based post data. There is a union type PostDataF combining the two for type hints but it cannot be constructed.

All of these types are Functory, by providing a nmap function that takes a function for each of the generic parameters. For example, see the ResponseF class below.

class ResponseF(Generic[A, B, C]):
   ...
   statusText: str
   httpVersion: str
   cookies: List[A]
   headers: List[B]
   content: C
   ...

   def nmap(
       self: "ResponseF[A, B, C]",
       f: Func[A, W],
       g: Func[B, X],
       h: Func[C, Y],
   ) -> "ResponseF[W, X, Y]":
       return replace(
           self,  # type: ignore[arg-type]
           cookies=list(map(f, self.cookies)),
           headers=list(map(g, self.headers)),
           content=h(self.content),
       )

Morphisms

Currently there are just 2 helper morphisms. harf_cata is a general catamorphsim, and harf which helps you build an algebra for harf_cata by taking explicit functions for each HAR type. All functions can be imported from harf_serde.morphism or directly from harf_serde.

For example, if you wanted to count the number of times the string "key" is in headers you could do the following

harf(
    default=0,
    header=lambda h: h.count("key"),
    request=lambda r: sum(r.headers),
    response=lambda r: sum(r.headers),
    entry=lambda e: e.request + e.response,
    log=lambda l: sum(l.entries),
)(har_data)

Canonical/Basic types

For simple usages there are also type aliases for the canonical HAR structure. I.E. Response = ResponseF[Cookie, Header, Content]. All types can be imported from harf_serde.har or directly from harf_serde.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

harf-serde-1.2b5.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

harf_serde-1.2b5-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file harf-serde-1.2b5.tar.gz.

File metadata

  • Download URL: harf-serde-1.2b5.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.9

File hashes

Hashes for harf-serde-1.2b5.tar.gz
Algorithm Hash digest
SHA256 cc899b2fcbcb5675316ac3d5969cb8b7c48dbc0231bd7053d8a5995a9e9d89a4
MD5 69b4f499cd8b9600ba4a2124d859737c
BLAKE2b-256 db1478b02b781c919fded294f9230821f670eaea740afd3200dc590e9ea9eba3

See more details on using hashes here.

File details

Details for the file harf_serde-1.2b5-py3-none-any.whl.

File metadata

  • Download URL: harf_serde-1.2b5-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.9

File hashes

Hashes for harf_serde-1.2b5-py3-none-any.whl
Algorithm Hash digest
SHA256 eefa19c3cf89583bc1e337851d0fa133514aee6ae67c0129fd85bb0db0d58782
MD5 9583a2057645fcb5223935ceaf21d033
BLAKE2b-256 82ab274b19c8c3a438439bc042a3dabbf6584ba07eab3cb04b18fb163a0f1f25

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page