Skip to main content

Build Status PyPI version Downloads

DEPRECATED

Please use apitist package

python-apitist

Brand new way to test your API

Installation

Run the following command in your command line::

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

Using random data generator

First of all create an instance of random class:

from apitist.random import Randomer
rand = Randomer()

Now, you can add custom hooks for different types:

rand.add_type(str, lambda: str(random.random()))
rand.add_type(float, lambda: random.random())

Or using add_types:

types = {
    str: lambda: str(random.random()),
    float: lambda: random.random()
}
rand.add_types(types)

Now you can create random object for given type or any attrs class with defined types:

import attr
import typing

rand.object(str) # '0.6147789314561384'
rand.object(float) # 0.4664297665239271

@attr.s
class Data:
    value1: str = attr.ib()
    value2: typing.List[str] = attr.ib()
    value3: typing.Tuple[float] = attr.ib()

print(rand.object(Data))
# Data(
#   value1='0.491058956716827',
#   value2=['0.6568036485871975'],
#   value3=(0.8603579349502298,)
# )

It is better to use it with Faker. Just define different subclasses for str and add different hooks for them. By this you could create different data for different str fields.

Also, using with RequestConverterHook and ResponseConverterHook you could easily create random json objects which would be send to server.

Metadata

Release files for python-apitist 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-apitist 0.5.2
File Size Uploaded Provenance Actions
python-apitist-0.5.2.tar.gz 34.0 kB Without provenance Details for python-apitist-0.5.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-apitist 0.5.2
File Interpreter ABI Platform Actions
python_apitist-0.5.2-py2.py3-none-any.whl Python 3, Python 2 none any Details for python_apitist-0.5.2-py2.py3-none-any.whl

Total release size: 56.2 kB

Release files / python-apitist-0.5.2.tar.gz

Download URL python-apitist-0.5.2.tar.gz
Size 34.0 kB
Tags Source
SHA-256 checksum
How to use checksums
aed80683be8f1c80fa3bf2179d25b75ce676d1b1b61dcd14f9140eec822c9c17
BLAKE2b-256 checksum
How to use checksums
438aeebf382294e79cdae85f693e148d344ab3423853b42b4a16c977f8c98b54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

Release files / python_apitist-0.5.2-py2.py3-none-any.whl

Download URL python_apitist-0.5.2-py2.py3-none-any.whl
Size 22.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9116c80297d2df7d68165ab567bacf6c63a82d4dbf4b29e81eb5d2e37d01f424
BLAKE2b-256 checksum
How to use checksums
124f937ae37f4b9e243b7676a2987fdb6adf41969ad969c821aad209e40f7ff1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

Security for python-apitist 0.5.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page