⚙️ Server Thread
Launch a WSGI or ASGI Application in a background thread with werkzeug or uvicorn.
This application was created for 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):
# 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:
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:
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 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:
import server_thread
print(server_thread.Report())
🚀 Examples
Minimal examples for using server-thread with common micro-frameworks.
💨 FastAPI
import requests
from fastapi import FastAPI
from server_thread import ServerThread
app = FastAPI()
@app.get("/")
def root():
return {"message": "Howdy!"}
server = ServerThread(app)
requests.get(f"http://{server.host}:{server.port}/").json()
⚗️ Flask
import requests
from flask import Flask
from server_thread import ServerThread
app = Flask("testapp")
@app.route("/")
def howdy():
return {"message": "Howdy!"}
server = ServerThread(app)
requests.get(f"http://{server.host}:{server.port}/").json()
Metadata
Release files for server-thread 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| server_thread-0.3.0.tar.gz | 6.5 kB | Without provenance | Details for server_thread-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| server_thread-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for server_thread-0.3.0-py3-none-any.whl |
Total release size: 13.1 kB
Release files / server_thread-0.3.0.tar.gz
| Download URL | server_thread-0.3.0.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2b6219d452cf79fa527bf559c35e7acb59ce38660492a65a185fa5cfddae295
|
|
BLAKE2b-256 checksum How to use checksums |
de67738f229f73364615252fa208c82cb45a93b72e7d439bd75e0d85d4f5d74b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Release files / server_thread-0.3.0-py3-none-any.whl
| Download URL | server_thread-0.3.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd1e2ee15e0d448e1c0e479aec1417368364ec7785c92c2973a17e9ce458dc00
|
|
BLAKE2b-256 checksum How to use checksums |
bf853ffc300dc13ea00a4fe063338ee9352a322a8932338ed45a18473d1a4806
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Security for server-thread 0.3.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.