Skip to main content

Build Status   Version

Overview

Flask-Loopback enables you to use written Flask applications in your code to mock actual web services. This is useful if you are writing a client that will use an existing web service and would like to know how well it will interact with the real thing.

Flask-Loopback does this without actually sending HTTP requests over the network, but rather through stubbing the requests package so that only requests directed at your mock will arrive at their destination.

Doing this is very simple. You probably already have a flask application somewhere that you'd like to use

# myapp.py
>>> import flask

>>> app = flask.Flask(__name__)

>>> @app.route("/some/path")
... def hello():
...     return "hello!"

When you want to actually use it, you activate the loopback on a specified address:

>>> import requests
>>> from flask_loopback import FlaskLoopback

>>> loopback = FlaskLoopback(app)

>>> with loopback.on(("some-address.com", 80)):
...    print(requests.get("http://some-address.com/some/path").content.decode("utf-8"))
hello!

To help you perform more actions before and after requests, you can register request context functions to be called around actual requests (this is in addition to the default handlers provided by Flask):

>>> from contextlib import contextmanager

>>> @loopback.register_request_context_handler
... @contextmanager
... def request_handler(request):
...     # do something before request handling
...     yield
...     # do something after request handling

SSL

SSL is disabled by default, but you can easily activate it:

>>> with loopback.on(("some-address.localdomain", 443)):
...    requests.get("https://some-address.localdomain/some/path") # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
	...
SSLError
>>> with loopback.on(("some-address.localdomain", 443), ssl=True):
...    requests.get("https://some-address.localdomain/some/path") # doctest: +IGNORE_EXCEPTION_DETAIL
<Response [200]>

Licence

BSD3 (See LICENSE)

Metadata

Release files for Flask-Loopback 1.6.0

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

Source distribution (sdist)

Source distribution for Flask-Loopback 1.6.0
File Size Uploaded Provenance Actions
flask_loopback-1.6.0.tar.gz 12.0 kB Without provenance Details for flask_loopback-1.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Flask-Loopback 1.6.0
File Interpreter ABI Platform Actions
Flask_Loopback-1.6.0-py3-none-any.whl Python 3 none any Details for Flask_Loopback-1.6.0-py3-none-any.whl

Total release size: 19.5 kB

Release files / flask_loopback-1.6.0.tar.gz

Download URL flask_loopback-1.6.0.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
44eedbedf60ef4fc933a506e10a0b0bf70e670fcf1cb11936813c66b4b1fcc2d
BLAKE2b-256 checksum
How to use checksums
63fff4d30d28df6d2c6fd9ad370eaed516c31b55a3973456e749bec48b34b4f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / Flask_Loopback-1.6.0-py3-none-any.whl

Download URL Flask_Loopback-1.6.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ac1a2d763ceb302b99c3ebbfbc73c4d0781e11498e11f8262b390ab01154553
BLAKE2b-256 checksum
How to use checksums
73724f25c57911bc5df8e89d029a1681a7c2b05731f963079d57d041d5390915
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Security for Flask-Loopback 1.6.0

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