Skip to main content

A library facilitating work with asynchronous APIs

Project description

Tests PyPI - Python Version PyPI License: MIT Code style: black Ruff codecov CodeFactor

Be Patient

bepatient is a library aimed at facilitating work with asynchronous applications. It allows for the repeated execution of specific actions until the desired effect is achieved.

Features

  • Set up and monitor requests for expected values.
  • Flexible comparison using various checkers and comparers.
  • Configure multiple conditions to be met by response.
  • Inspect various aspects of the response (body, status code, headers).
  • Detailed logs (containing cURLs), facilitating the analysis of the test process.
  • Retry mechanism with customizable retries and delay.

Installation

To install bepatient, you can use pip:

pip install bepatient

bepatient supports Python 3.10+

Basic Usage

Using RequestsWaiter object:

from requests import get

from bepatient import RequestsWaiter

waiter = RequestsWaiter(request=get("https://example.com/api"))
waiter.add_checker(comparer="contain", expected_value="string")
waiter.run()

response = waiter.get_result()

assert response.status_code == 200

Simple way:

from requests import get

from bepatient import wait_for_value_in_request

response = wait_for_value_in_request(
    request=get("https://example.com/api"),
    comparer="contain",
    expected_value="string"
)
assert response.status_code == 200

If we need add more than one checker:

from requests import get

from bepatient import wait_for_values_in_request

list_of_checkers = [
    {
        "checker": "json_checker",
        "comparer": "contain",
        "expected_value": "string"
    },
    {
        "checker": "headers_checker",
        "comparer": "is_equal",
        "expected_value": "cloudflare",
        "dict_path": "Server",
    },
]
response = wait_for_values_in_request(
    request=get("https://example.com/api"),
    checkers=list_of_checkers,
    retries=5,
)
assert response.status_code == 200

License

MIT License

Copyright (c) 2023-present Dawid Szaniawski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bepatient-1.0.0.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bepatient-1.0.0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file bepatient-1.0.0.tar.gz.

File metadata

  • Download URL: bepatient-1.0.0.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for bepatient-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f2407bf55b29b2729b3e067966f64c7decd6d3dc7bcf9296288a88d0beadfe3e
MD5 1add6f4b1fbb8a24dfd20bc8ac5ca894
BLAKE2b-256 861a75de771f8e51386089fa80293b0b6fb487dbd607d5234e50fad9d6404ddf

See more details on using hashes here.

File details

Details for the file bepatient-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: bepatient-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for bepatient-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cc402fb158d1a6c7b9a0c03aa518d019fe52cde24774b4480f5338eab893c9c
MD5 9fa6a63e4f8ce2d0dfb96eebe7a63c6b
BLAKE2b-256 04fe7377157062aefc074aab25e009afc4a413a8daf8055687a02231a8752c5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page