Note: A new, lighterweight, more modern replacement: ho
http2py: (Http) requests for humans
Tools to make python functions that call http web services, so the function takes the python arguments you care about and returns the python object you want, with http kept under the hood.
pip install http2py
Say what the request looks like and what you want back from the response, and get a function:
from http2py import mk_request_function
get_stars = mk_request_function(
{
"method": "get",
"url_template": "https://api.example.com/repos/{owner}/{name}",
"output_trans": lambda response: response.json()["stars"],
}
)
The result is meant to be a method, so its first argument (self) is ignored. It is called like this, and dispatch= is the seam that lets you swap the real requests.request for your own function, which is how you test without a network:
class FakeResponse:
def json(self):
return {"stars": 3}
def fake_dispatch(method, url, **kwargs):
print(method, url)
return FakeResponse()
get_stars = mk_request_function(
{
"method": "get",
"url_template": "https://api.example.com/repos/{owner}/{name}",
"output_trans": lambda response: response.json()["stars"],
},
dispatch=fake_dispatch,
)
get_stars(
None, owner="thor", name="x"
) # prints "get https://api.example.com/repos/thor/x", returns 3
For a service described by an OpenAPI spec, http2py.HttpClient builds one such function per route, and mk_cli makes a command line from it.
Background
Tools to create python binders to http web services. Here, we develop python data access to web content through http request such as web services or web pages.
The story is as follows: You found something on the web that you'd like to interact with.
- This could be data you'd like to have access to,
- or some actions you'd like to perform -- such as search, posting an article, buying some bitcoin, etc..
- If you're really lucky, someone's already written a python layer to do what you want to do.
- If you're just lucky, the resource comes with a clear interface definition that makes it easy for you to write your own python for.
- If you're less lucky, you'll have to decipher some bad documentation of the API, or even write your own bots, crawlers and parsers to get what you want.
We want to make that all easier for you.
What we'll focus on for now is the fundamental common aspect of making a python layer to the http requests.
"But... the excellent requests library already provides the python wrapper to http!" you say. Yes, and we thank the requests developers for that. It is indeed an excellent package that we won't have to write now!
We'd like to build from there, cover more annoying boilerplate, and get you closer, faster, to the functionality you actually need: Functions with the python types you're using in your code, that responds with python objects you can directly use in your code.
The development of requests (including the recommended add-ons) could be said to be facing the metal (raw http mechanics) and building interfaces with humans in mind. By contrast, we want to face the human and build adapters to communicate with the metal. That is, in our case, the fact that http is under the hood shouldn't even be visible (unless it needs to).
It's in honor of the inspiration of "designing for humans" that we extend requests' tag-line, to "requests for humans".
The approach
As always, we favor expressiveness, boilerplate minimization, separation of concerns, and a layered approach that incrementally transforms and enhance to get us from where we are to where we want to be.
So for py2request, where are we and where do we want to be?
What we have: We have some http accessible resources. For instance, a perfectly well structured API specification of a REST webservice, a very messy website, or anything in between.
What we'd like: A Python interface to these web stuff. That is, we want to talk python to the resources, and have it talk python back to us. Further, we want this conversation to be to the point; we don't want to have to say more than the exact necessary, and don't want responses containing anything but exactly what we want and how we want it. Finally, we'd like to get this with minimum effort -- letting default choices be made for us, but being able to make our own choices if we want.
Is that too much to ask?
In the layered approach we'll go from function specifications, to functions returning python Request objects, which we can then wrap further to create functions actually executing the request, getting back a Response object, and wrap further to get the final python output type.
So the objects in this pipeline are:
- Specification
- Request
- Response
- Final python object
Metadata
Release files for http2py 0.1.44
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| http2py-0.1.44.tar.gz | 52.2 kB | Without provenance | Details for http2py-0.1.44.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| http2py-0.1.44-py3-none-any.whl | Python 3 | none | any | Details for http2py-0.1.44-py3-none-any.whl |
Total release size: 93.6 kB
Release files / http2py-0.1.44.tar.gz
| Download URL | http2py-0.1.44.tar.gz |
|---|---|
| Size | 52.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d96a7e700a72936bf00ffcdfc7854e9654f0439eed9516c0ea13d058a1b886f6
|
|
BLAKE2b-256 checksum How to use checksums |
6490c14f619de43e97239dbeb555416d8c6b30466e113da8f4e809345fcc117c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / http2py-0.1.44-py3-none-any.whl
| Download URL | http2py-0.1.44-py3-none-any.whl |
|---|---|
| Size | 41.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb7375020b52a01f5ce4ffb2cdb4d59338146bd357279f8d067c8d6f407717d5
|
|
BLAKE2b-256 checksum How to use checksums |
f689f7257f29df3d7b91fa0757b552e371d97b69781e190e140272e0da6a50db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for http2py 0.1.44
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.