Flask-Loopback


NameFlask-Loopback JSON
Version 1.6.0 PyPI version JSON
download
home_pagehttps://github.com/vmalloc/flask-loopback
SummaryLibrary for faking HTTP requests using flask applications without actual network operations
upload_time2024-09-25 05:07:45
maintainerNone
docs_urlNone
authorRotem Yaari
requires_pythonNone
licenseBSD3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ![Build Status](https://secure.travis-ci.org/vmalloc/Flask-Loopback.png)   ![Version](https://img.shields.io/pypi/v/Flask-Loopback.svg)

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

```python
# 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:

```python
>>> 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):

```python
>>> 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:

```python
>>> 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`)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vmalloc/flask-loopback",
    "name": "Flask-Loopback",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Rotem Yaari",
    "author_email": "vmalloc@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/63/ff/f4d30d28df6d2c6fd9ad370eaed516c31b55a3973456e749bec48b34b4f6/flask_loopback-1.6.0.tar.gz",
    "platform": null,
    "description": "![Build Status](https://secure.travis-ci.org/vmalloc/Flask-Loopback.png) &nbsp; ![Version](https://img.shields.io/pypi/v/Flask-Loopback.svg)\n\nOverview\n========\n\nFlask-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.\n\nFlask-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.\n\nDoing this is very simple. You probably already have a flask application somewhere that you'd like to use\n\n```python\n# myapp.py\n>>> import flask\n\n>>> app = flask.Flask(__name__)\n\n>>> @app.route(\"/some/path\")\n... def hello():\n...     return \"hello!\"\n\n```\n\nWhen you want to actually use it, you activate the loopback on a specified address:\n\n```python\n>>> import requests\n>>> from flask_loopback import FlaskLoopback\n\n>>> loopback = FlaskLoopback(app)\n\n>>> with loopback.on((\"some-address.com\", 80)):\n...    print(requests.get(\"http://some-address.com/some/path\").content.decode(\"utf-8\"))\nhello!\n\n```\n\nTo 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):\n\n```python\n>>> from contextlib import contextmanager\n\n>>> @loopback.register_request_context_handler\n... @contextmanager\n... def request_handler(request):\n...     # do something before request handling\n...     yield\n...     # do something after request handling\n\n```\n\nSSL\n===\n\nSSL is disabled by default, but you can easily activate it:\n\n```python\n>>> with loopback.on((\"some-address.localdomain\", 443)):\n...    requests.get(\"https://some-address.localdomain/some/path\") # doctest: +IGNORE_EXCEPTION_DETAIL\nTraceback (most recent call last):\n\t...\nSSLError\n>>> with loopback.on((\"some-address.localdomain\", 443), ssl=True):\n...    requests.get(\"https://some-address.localdomain/some/path\") # doctest: +IGNORE_EXCEPTION_DETAIL\n<Response [200]>\n\n```\n\n\n\nLicence\n=======\n\nBSD3 (See `LICENSE`)\n\n",
    "bugtrack_url": null,
    "license": "BSD3",
    "summary": "Library for faking HTTP requests using flask applications without actual network operations",
    "version": "1.6.0",
    "project_urls": {
        "Homepage": "https://github.com/vmalloc/flask-loopback"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "73724f25c57911bc5df8e89d029a1681a7c2b05731f963079d57d041d5390915",
                "md5": "b57e8a9b41ee3d699af124969460508a",
                "sha256": "8ac1a2d763ceb302b99c3ebbfbc73c4d0781e11498e11f8262b390ab01154553"
            },
            "downloads": -1,
            "filename": "Flask_Loopback-1.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b57e8a9b41ee3d699af124969460508a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7516,
            "upload_time": "2024-09-25T05:07:44",
            "upload_time_iso_8601": "2024-09-25T05:07:44.420687Z",
            "url": "https://files.pythonhosted.org/packages/73/72/4f25c57911bc5df8e89d029a1681a7c2b05731f963079d57d041d5390915/Flask_Loopback-1.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "63fff4d30d28df6d2c6fd9ad370eaed516c31b55a3973456e749bec48b34b4f6",
                "md5": "859b4187c8cdfd275f76f59b4f044dcb",
                "sha256": "44eedbedf60ef4fc933a506e10a0b0bf70e670fcf1cb11936813c66b4b1fcc2d"
            },
            "downloads": -1,
            "filename": "flask_loopback-1.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "859b4187c8cdfd275f76f59b4f044dcb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12004,
            "upload_time": "2024-09-25T05:07:45",
            "upload_time_iso_8601": "2024-09-25T05:07:45.395855Z",
            "url": "https://files.pythonhosted.org/packages/63/ff/f4d30d28df6d2c6fd9ad370eaed516c31b55a3973456e749bec48b34b4f6/flask_loopback-1.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-25 05:07:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vmalloc",
    "github_project": "flask-loopback",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "flask-loopback"
}
        
Elapsed time: 0.33030s