server-thread


Nameserver-thread JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/banesullivan/server-thread
SummaryLaunch a WSGI or ASGI Application in a background thread with werkzeug or uvicorn.
upload_time2022-07-27 23:24:59
maintainer
docs_urlNone
authorBane Sullivan
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ⚙️ Server Thread

[![Tests](https://github.com/banesullivan/server-thread/actions/workflows/test.yml/badge.svg)](https://github.com/banesullivan/server-thread/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/banesullivan/server-thread/branch/main/graph/badge.svg?token=S0HQ64FW8G)](https://codecov.io/gh/banesullivan/server-thread)
[![PyPI](https://img.shields.io/pypi/v/server-thread.svg?logo=python&logoColor=white)](https://pypi.org/project/server-thread/)
[![conda](https://img.shields.io/conda/vn/conda-forge/server-thread.svg?logo=conda-forge&logoColor=white)](https://anaconda.org/conda-forge/server-thread)

Launch a WSGI or ASGI Application in a background thread with werkzeug or uvicorn.

This application was created for [`localtileserver`](https://github.com/banesullivan/localtileserver)
and provides the basis for how it can launch an image tile server as a
background thread for visualizing data in Jupyter notebooks.

While this may not be a widely applicable library, it is useful for a few
Python packages I have created that require a background service.


## 🚀 Usage

Use the `ServerThread` with any WSGI or ASGI Application.

Start by creating a application (this can be a flask app or a simple app
like below):


```py
# Create some WSGI Application
from werkzeug import Request, Response

@Request.application
def app(request):
    return Response("howdy", 200)
```

Then launch the app with the `ServerThread` class:


```py
import requests
from server_thread import ServerThread

# Launch app in a background thread
server = ServerThread(app)

# Perform requests against the server without blocking
requests.get(f"http://{server.host}:{server.port}/").raise_for_status()
```


## ⬇️ Installation

Get started with `server-thread` to create applications that require a
WSGIApplication in the background.

### 🐍 Installing with `conda`

Conda makes managing `server-thread`'s dependencies across platforms quite
easy and this is the recommended method to install:

```bash
conda install -c conda-forge server-thread
```

### 🎡 Installing with `pip`

If you prefer pip, then you can install from PyPI: https://pypi.org/project/server-thread/

```
pip install server-thread
```

## 💭 Feedback

Please share your thoughts and questions on the [Discussions](https://github.com/banesullivan/server-thread/discussions) board.
If you would like to report any bugs or make feature requests, please open an issue.

If filing a bug report, please share a scooby `Report`:

```py
import server_thread
print(server_thread.Report())
```


## 🚀 Examples

Minimal examples for using `server-thread` with common micro-frameworks.


### 💨 FastAPI

```py
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def root():
    return {"message": "Howdy!"}


server = ServerThread(app)
requests.get(f"http://{server.host}:{server.port}/").json()
```

### ⚗️ Flask

```py
from flask import Flask

app = Flask("testapp")


@app.route("/")
def howdy():
    return {"message": "Howdy!"}


server = ServerThread(app)
requests.get(f"http://{server.host}:{server.port}/").json()
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/banesullivan/server-thread",
    "name": "server-thread",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Bane Sullivan",
    "author_email": "hello@banesullivan.com",
    "download_url": "https://files.pythonhosted.org/packages/4b/16/b3a3e54dac1a557384aafef25edd1909586904937f72128eeadebfb15673/server-thread-0.2.0.tar.gz",
    "platform": null,
    "description": "# \u2699\ufe0f Server Thread\n\n[![Tests](https://github.com/banesullivan/server-thread/actions/workflows/test.yml/badge.svg)](https://github.com/banesullivan/server-thread/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/banesullivan/server-thread/branch/main/graph/badge.svg?token=S0HQ64FW8G)](https://codecov.io/gh/banesullivan/server-thread)\n[![PyPI](https://img.shields.io/pypi/v/server-thread.svg?logo=python&logoColor=white)](https://pypi.org/project/server-thread/)\n[![conda](https://img.shields.io/conda/vn/conda-forge/server-thread.svg?logo=conda-forge&logoColor=white)](https://anaconda.org/conda-forge/server-thread)\n\nLaunch a WSGI or ASGI Application in a background thread with werkzeug or uvicorn.\n\nThis application was created for [`localtileserver`](https://github.com/banesullivan/localtileserver)\nand provides the basis for how it can launch an image tile server as a\nbackground thread for visualizing data in Jupyter notebooks.\n\nWhile this may not be a widely applicable library, it is useful for a few\nPython packages I have created that require a background service.\n\n\n## \ud83d\ude80 Usage\n\nUse the `ServerThread` with any WSGI or ASGI Application.\n\nStart by creating a application (this can be a flask app or a simple app\nlike below):\n\n\n```py\n# Create some WSGI Application\nfrom werkzeug import Request, Response\n\n@Request.application\ndef app(request):\n    return Response(\"howdy\", 200)\n```\n\nThen launch the app with the `ServerThread` class:\n\n\n```py\nimport requests\nfrom server_thread import ServerThread\n\n# Launch app in a background thread\nserver = ServerThread(app)\n\n# Perform requests against the server without blocking\nrequests.get(f\"http://{server.host}:{server.port}/\").raise_for_status()\n```\n\n\n## \u2b07\ufe0f Installation\n\nGet started with `server-thread` to create applications that require a\nWSGIApplication in the background.\n\n### \ud83d\udc0d Installing with `conda`\n\nConda makes managing `server-thread`'s dependencies across platforms quite\neasy and this is the recommended method to install:\n\n```bash\nconda install -c conda-forge server-thread\n```\n\n### \ud83c\udfa1 Installing with `pip`\n\nIf you prefer pip, then you can install from PyPI: https://pypi.org/project/server-thread/\n\n```\npip install server-thread\n```\n\n## \ud83d\udcad Feedback\n\nPlease share your thoughts and questions on the [Discussions](https://github.com/banesullivan/server-thread/discussions) board.\nIf you would like to report any bugs or make feature requests, please open an issue.\n\nIf filing a bug report, please share a scooby `Report`:\n\n```py\nimport server_thread\nprint(server_thread.Report())\n```\n\n\n## \ud83d\ude80 Examples\n\nMinimal examples for using `server-thread` with common micro-frameworks.\n\n\n### \ud83d\udca8 FastAPI\n\n```py\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n\n@app.get(\"/\")\ndef root():\n    return {\"message\": \"Howdy!\"}\n\n\nserver = ServerThread(app)\nrequests.get(f\"http://{server.host}:{server.port}/\").json()\n```\n\n### \u2697\ufe0f Flask\n\n```py\nfrom flask import Flask\n\napp = Flask(\"testapp\")\n\n\n@app.route(\"/\")\ndef howdy():\n    return {\"message\": \"Howdy!\"}\n\n\nserver = ServerThread(app)\nrequests.get(f\"http://{server.host}:{server.port}/\").json()\n```\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Launch a WSGI or ASGI Application in a background thread with werkzeug or uvicorn.",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/banesullivan/server-thread"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6429454b1c597eb418f4f95499eabbb8d32c375c50043695fab456ea8a7e8c27",
                "md5": "da657ddfd87d69359bb5dad8714790b6",
                "sha256": "2b779e54ec96debadc72b9622f7365b191ed444a230b38bd31b89ea8b7166a38"
            },
            "downloads": -1,
            "filename": "server_thread-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "da657ddfd87d69359bb5dad8714790b6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8512,
            "upload_time": "2022-07-27T23:24:56",
            "upload_time_iso_8601": "2022-07-27T23:24:56.085845Z",
            "url": "https://files.pythonhosted.org/packages/64/29/454b1c597eb418f4f95499eabbb8d32c375c50043695fab456ea8a7e8c27/server_thread-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4b16b3a3e54dac1a557384aafef25edd1909586904937f72128eeadebfb15673",
                "md5": "7632997419fcb13014bfa1f1f9465f64",
                "sha256": "d89f80048b1c2ea311ab10665e955d8a075c7a823a06c80563714aff42c4ec12"
            },
            "downloads": -1,
            "filename": "server-thread-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7632997419fcb13014bfa1f1f9465f64",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7157,
            "upload_time": "2022-07-27T23:24:59",
            "upload_time_iso_8601": "2022-07-27T23:24:59.470534Z",
            "url": "https://files.pythonhosted.org/packages/4b/16/b3a3e54dac1a557384aafef25edd1909586904937f72128eeadebfb15673/server-thread-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-07-27 23:24:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "banesullivan",
    "github_project": "server-thread",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "server-thread"
}
        
Elapsed time: 5.15744s