Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wardpearce/obrequests
Modern typed requests for Python 3 built on-top of HTTPX
https://github.com/wardpearce/obrequests
async asyncio awaiting based http https object python requests rest sync type typed
Last synced: 19 days ago
JSON representation
Modern typed requests for Python 3 built on-top of HTTPX
- Host: GitHub
- URL: https://github.com/wardpearce/obrequests
- Owner: WardPearce
- License: gpl-3.0
- Created: 2020-06-30T02:59:43.000Z (over 4 years ago)
- Default Branch: Development
- Last Pushed: 2022-05-13T08:20:45.000Z (over 2 years ago)
- Last Synced: 2024-10-11T03:19:16.536Z (about 1 month ago)
- Topics: async, asyncio, awaiting, based, http, https, object, python, requests, rest, sync, type, typed
- Language: Python
- Homepage: https://obrequests.readthedocs.io/en/latest/
- Size: 258 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Object-Based Requests
Object-Based Requests reinvents the wheel around how HTTP requests are interfaced by developers, its built around reusability & static typing.## Index
- [Install](#install)
- [Docs](#docs)
- [Features](#features)
- [Example](#example)
- [Project example](/example)
- [Thanks to](#thanks-to)## Install
`pip3 install OBRequests>=2.0.0`## Docs
[obrequests.readthedocs.io](https://obrequests.readthedocs.io/en/latest/)## Features
- Unique route typing
- Documented
- Supports sync & async with a flick of a boolean
- Built on top of [HTTPX](https://github.com/encode/httpx) for stability and security.
- Supports all the amazing [features](https://github.com/encode/httpx#features) of HTTPX## Example
```py
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 = 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_route.get()
# The same as
request.base_.get(url="/posts")
except HTTPStatusError as error:
print(error)# Prints status code
request.posts_route.get(path_params={
"post_id": 1
})# Only needed for async
request.close_()
```## Thanks to
- [HTTPX](https://github.com/encode/httpx)