Brand new way to test your API
Project description
python-apitist
Brand new way to test your API
Installation
Actually project is not published on PyPi, so the only way:
pip install python-apitist
Default hooks
- RequestDebugLoggingHook
- RequestInfoLoggingHook
- PrepRequestDebugLoggingHook
- PrepRequestInfoLoggingHook
- ResponseDebugLoggingHook
- ResponseInfoLoggingHook
Example usage
from apitist.hooks import PrepRequestInfoLoggingHook, ResponseInfoLoggingHook
from apitist.requests import session
s = session()
PrepRequestInfoLoggingHook.formatter = "Best formatter {req.method} {req.url}"
s.add_prep_request_hook(PrepRequestInfoLoggingHook)
s.add_response_hook(ResponseInfoLoggingHook)
s.post("https://httpbin.org/post", params={"q": "test"})
Custom Hooks
from requests import Request, PreparedRequest, Response
from apitist.requests import session, RequestHook, PreparedRequestHook, ResponseHook
s = session()
class ReqHook(RequestHook):
def run(self, request: Request) -> Request:
print(request.url)
return request
class PrepReqHook(PreparedRequestHook):
def run(self, request: PreparedRequest) -> PreparedRequest:
print(request.url)
return request
class RespHook(ResponseHook):
def run(self, response: Response) -> Response:
print(response.url)
return response
s.add_request_hook(ReqHook)
s.add_prep_request_hook(PrepReqHook)
s.add_response_hook(RespHook)
s.get("https://ya.ru", params={"q": "test"})
Working with constructor
import attr
import typing
from apitist.constructor import converter
from apitist.hooks import RequestConverterHook, ResponseConverterHook
from apitist.requests import session
class ExampleType:
test = None
@attr.s
class ExampleStructure:
test: ExampleType = attr.ib()
@attr.s
class TestResponse:
args: typing.Dict = attr.ib()
data: str = attr.ib()
files: typing.Dict = attr.ib()
form: typing.Dict = attr.ib()
headers: typing.Dict = attr.ib()
json: ExampleStructure = attr.ib()
origin: str = attr.ib()
url: str = attr.ib()
s = session()
s.add_hook(RequestConverterHook)
s.add_hook(ResponseConverterHook)
def structure_example_type(data, type_):
example = ExampleType()
example.test = data
return example
def unstructure_example_type(data):
return data.test
converter.register_hooks(
ExampleType, structure_example_type, unstructure_example_type
)
t = ExampleType()
t.test = "test"
struc = ExampleStructure(t)
res = s.post("https://httpbin.org/post", data=struc).structure(TestResponse)
print(res.structured.json.test.test) # test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-apitist-0.0.4.tar.gz
(28.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python-apitist-0.0.4.tar.gz.
File metadata
- Download URL: python-apitist-0.0.4.tar.gz
- Upload date:
- Size: 28.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd3373112263e889cef83b6ff370ea9dedf9833d4a7afce1e33ed4a5bb9d203b
|
|
| MD5 |
226d5a6fcf2ee6b3cd434c97f1ca2426
|
|
| BLAKE2b-256 |
db1c03fabb77a92a6f5fbb86c9223c7d62a357912923a29065e28efb1d0382ae
|
File details
Details for the file python_apitist-0.0.4-py2.py3-none-any.whl.
File metadata
- Download URL: python_apitist-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 20.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47f1a425997157f11462822341511046f3b8464b74970c3d9ac3aaf3ae0d0d5c
|
|
| MD5 |
16de862d0b7163fb3ea7a7eb94e987f7
|
|
| BLAKE2b-256 |
24c8e06d21e819f0e7a81f4cc9123c4a716f588b2c7588cde78489ffccacb220
|