Flask

As a Flask user, you can use the power of HTTPX using its synchronous interface.

Here is a simple example:

from flask import Flask
from httpx import Client
from httpx import Limits

app = Flask(__name__)
client = Client(limits=Limits(max_connections=1000))

@app.route("/")
def main():
    response = client.get('https://www.encode.io')
    return str(response.status_code)

Now let's do some load testing using the popular load testing tool Locust.

Here are the test results:

pypi

We got only ±20 RPS, which is not very good.

Now let's change the httpx.Client to hishel.CacheClient and do the same tests again.

from flask import Flask
from hishel import CacheClient
from httpx import Limits

app = Flask(__name__)
client = CacheClient(limits=Limits(max_connections=1000))

@app.route("/")
def main():
    response = client.get('https://www.encode.io')
    return str(response.status_code)

Here are the test results:

pypi

Now we have more than ±800 RPS using the power of HTTP caching.