Skip to main content

Httpea

Httpea is an abstraction library which provides a set of classes that represent different parts of the http communication process. These classes can be used to build custom http clients and servers, or to extend existing ones.

The idea behind this library is to provide an interface for manipulating http requests and responses in a way that is easy to use and understand.

Features

  • HttpRequest and HttpResponse classes for representing http requests and responses
  • Multipart body parsing for handling file uploads
  • Fast and efficient parsing and building of http messages from scratch
  • Fast routing and router for your application
  • Query string parsing
  • Cookie parsing and building

Installation

You can install Httpea using pip:

pip install httpea

,or with poetry:

poetry add httpea

Usage

This is an example guide of how basic usage of the library looks like. More detailed examples can be found in tests.

HttpRequest

HttpRequest objects can be compared, they support query string parsing, cookies, headers and body parsing, including multipart body parsing.

from httpea import HttpRequest, HttpCookie

request = HttpRequest(HttpRequest.GET, "/" ,query_string="name=John&age=30")
# set headers
request.headers["Content-Type"] = "application/json"
# set body
request.body.write(b"Hello, World!")
# set cookies
request.cookies["session"] = "1234567890"

assert isinstance(request.cookies["session"], HttpCookie)
assert request.query_string["name"] == "John"
assert request.query_string["age"] == 30
assert str(request.query_string) == "name=John&age=30"

HttpResponse

Same like HttpRequest, HttpResponse objects can be compared, they support cookies, headers and body writing.

from httpea import HttpResponse, HttpCookie, HttpStatus

response = HttpResponse("Example response", HttpStatus.OK)

# write body
response.write(b"Hello, World!")

# set cookies
response.cookies.append(HttpCookie("cookie-name", "cookie-value", secure=True, http_only=True))

Route and Router

from httpea import Route

route = Route("/example/{pattern}")
result = route.match("/example/test")

assert result
assert result["pattern"] == "test"
assert not route.match("/example")

# wildcard route
route = Route("/example/*")
assert route.match("/example/test")
assert route.match("/example/test/123")
assert not route.match("/invalid")
from httpea import Router, HttpRequest, HttpNotFoundError

router = Router()
router.append("/users/{user_id}", lambda request, response, user_id: response.write(user_id), HttpRequest.GET)

try:
    route, callback = router.match("/users/123", HttpRequest.GET)
except HttpNotFoundError:
    pass

Metadata

Release files for httpea 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for httpea 1.0.0
File Size Uploaded
httpea-1.0.0.tar.gz 15.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for httpea 1.0.0
File Interpreter ABI Platform
httpea-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.7 kB

Release files / httpea-1.0.0.tar.gz

Download URL httpea-1.0.0.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8c224cf5233aedb4024f293d2b0045438233dd1aba70409a236a802b11e10141
BLAKE2b-256 checksum
How to use checksums
30fc2be3a1e1843daccb44c5ff93257c95d356fd7d31961edb307a30b14cfd3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.8.18 Linux/6.5.0-1022-azure

Release files / httpea-1.0.0-py3-none-any.whl

Download URL httpea-1.0.0-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a88778a016396be16f8acd7281d418e4d68dae9c2e354f6082aed792048fc0e6
BLAKE2b-256 checksum
How to use checksums
f6fe6432ec5f6030077af1b265ed2256613239b813c86af8d426ecc2ff5f188a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.8.18 Linux/6.5.0-1022-azure

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page