Object-Based Requests
OBRequests is a modern typed requests library for Python 3 built on-top of HTTPX. It aims to eliminate common boilerplate code when creating API wrappers and makes supporting async & sync python together easy!
Index
Install
pip3 install OBRequests>=2.0.0
Docs
Features
- Unique route typing
- Documented
- Supports sync & async with a flick of a boolean
- Built on top of HTTPX for stability and security.
- Supports all the amazing features of HTTPX
Example
from OBRequests import (
OBRequests, Response, CallBack, Route,
Get, json, raise_for_status,
HTTPStatusError, AnyStatus, BasicAuth
)
def custom_response(resp: Response, is_get: bool = False,
**kwargs) -> None:
if is_get:
print(resp.status_code)
else:
raise NotImplementedError()
class Requests(OBRequests):
posts = Route(
"/posts/{post_id}",
responses={
AnyStatus: CallBack(raise_for_status)
},
path_params={
"post_id": "404_error"
},
methods=[
Get(
responses={
200: CallBack(custom_response, is_get=True),
201: ConditionalCallBack(
awaiting=CallBack(custom_response, is_get=True),
blocking=CallBack(custom_response, is_get=False)
)
},
auth=BasicAuth("different", "password")
),
],
auth=BasicAuth("username", "password")
)
request = Requests(
responses={
200: CallBack(json)
},
base_url="https://jsonplaceholder.typicode.com",
awaiting=False,
globals_={
"example": True
}
)
try:
request.posts.get()
except HTTPStatusError as error:
print(error)
# Prints status code
request.posts.get(path_params={
"post_id": 1
})
# Returns phased JSON
request.base_.get(url="/posts")
# Only needed for async
request.close_()
Thanks to
Metadata
Release files for OBRequests 2.0.1
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 |
|---|---|---|---|---|
| OBRequests-2.0.1.tar.gz | 20.2 kB | Without provenance | Details for OBRequests-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| OBRequests-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for OBRequests-2.0.1-py3-none-any.whl |
Total release size: 45.1 kB
Release files / OBRequests-2.0.1.tar.gz
| Download URL | OBRequests-2.0.1.tar.gz |
|---|---|
| Size | 20.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f286799add86b6f5440bca6926d2fd8a314de523339df2374fae0a0eaab2f26
|
|
BLAKE2b-256 checksum How to use checksums |
034c289c15edf4650531965df9b51930c13166834c863586e0bf469345c901d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / OBRequests-2.0.1-py3-none-any.whl
| Download URL | OBRequests-2.0.1-py3-none-any.whl |
|---|---|
| Size | 24.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64c94e846e565bc0a751d79390735c037061a4ef320947dcf8d38519a2fd7f1a
|
|
BLAKE2b-256 checksum How to use checksums |
7c1d6c880c93a805d87bae07715b1197af681a98af61ece6c02d4a262386309b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Security for OBRequests 2.0.1
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.