thttp
thttp is a single file, lightweight, well-tested wrapper around urllib that's intended to be copied directly into your project.
It's features include:
- Making GET, POST, PATCH, PUT, HEAD and OPTIONS requests
- Sending query parameters with your request
- Encoding JSON payloads for POST, PATCH and PUT requests
- Encoding form-encoded payloads for POST, PATCH and PUT request
- Sending custom headers with any request
- Disabling SSL certificate verification for local testing / corporate proxies
- Following (or not following) redirects
- Sending through a CookieJar object that can be reused between requests
- Authenticating with HTTP basic auth
- Specifying a custom timeout for your request
- Decompressing gzipped content in the response
- Loading JSON from the response
- Returning error responses instead of throwing exceptions from
urllib pretty()function for printing responses- Ability to upload files using the
{"file": open("file.png", "rb")}style
Future features:
- Better detection of JSON responses
- Improve handling of non-utf-8 requests
- Improve handling of non-utf-8 responses
Note: this project is not intended to solve all use cases that can be achieved with urllib, requests, httpx, or other HTTP libraries. The intent is to provide a lightweight tool that simplifies some of the most common use cases for developers.
Installation
copy thttp.py directly into your project:
curl https://raw.githubusercontent.com/sesh/thttp/main/thttp.py > thttp.py
Or, install with pip:
python3 -m pip install thttp
Basic Usage
See the tests for examples of usage, but, effectively it's as simple as:
from thttp import request
response = request("https://httpbingo.org/get", params={"data": "empty"})
response.json
# {'args': {'data': ['empty']}, 'headers': {'Accept-Encoding': ['identity'], 'Fly-Client-Ip': ['45.76.105.111'], 'Fly-Forwarded-Port': ['443'], 'Fly-Forwarded-Proto': ['https'], 'Fly-Forwarded-Ssl': ['on'], 'Fly-Region': ['hkg'], 'Fly-Request-Id': ['01F6P2WQAY1NGPRDCXV9H60XW5'], 'Host': ['httpbingo.org'], 'User-Agent': ['Python-urllib/3.8'], 'Via': ['1.1 fly.io'], 'X-Forwarded-For': ['45.76.105.111, 77.83.142.42'], 'X-Forwarded-Port': ['443'], 'X-Forwarded-Proto': ['https'], 'X-Forwarded-Ssl': ['on'], 'X-Request-Start': ['t=1622091390302198']}, 'origin': '45.76.105.111, 77.83.142.42', 'url': 'https://httpbingo.org/get?data=empty'}
response.status
# 200
Running the tests
> python3 -m unittest thttp.py
And to check the coverage:
> coverage run -m unittest thttp.py
> coverage html && open htmlcov/index.html
Run black before committing any changes.
> black thttp.py
Packaging for release
rm dist/*
python3 -m build
python3 -m twine upload dist/*
License
This code is currently released under the UNLICENSE and considered public domain. If more appropriate for your usage you may consider this project released under the MIT License.
Metadata
Release files for thttp 1.3.0
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 |
|---|---|---|---|---|
| thttp-1.3.0.tar.gz | 6.7 kB | Without provenance | Details for thttp-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| thttp-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for thttp-1.3.0-py3-none-any.whl |
Total release size: 13.8 kB
Release files / thttp-1.3.0.tar.gz
| Download URL | thttp-1.3.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fceff289adc386121e275a35b3860759d2346b73e073fc64c3a3677c7f3d18a2
|
|
BLAKE2b-256 checksum How to use checksums |
a43481ab9f0e899144eb124eadb90aa3dd7940700f8f7cac22ba44e82d3b27cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / thttp-1.3.0-py3-none-any.whl
| Download URL | thttp-1.3.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36f18932385e840ffb18821598cd5e7d112a3f2a79f068f86cf9ddfc044e71ff
|
|
BLAKE2b-256 checksum How to use checksums |
f4d984a069a01989d7462d0dff7d7dd69667197db5ba4497ba45011cb7800bac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for thttp 1.3.0
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.