an extensible async background server
Project description
servir
an extensible async background server for python
table of contents
installation
pip install servir
usage
import pathlib
import requests
from servir import Provider
# create a provider
provider = Provider()
### File (supports range requests)
path = pathlib.Path("hello.txt")
path.write_text("hello, world")
file_resource = provider.create(path)
response = requests.get(file_resource.url)
assert response.text == "hello, world"
assert "text/plain" in response.headers["Content-Type"]
### Directory (supports range requests)
root = pathlib.Path("data_dir")
root.mkdir()
(root / "hello.txt").write_text("hello, world")
dir_resource = provider.create(root)
response = requests.get(file_resource.url + "/hello.txt")
assert response.text == "hello, world"
assert "text/plain" in response.headers["Content-Type"]
### In-Memory
data = "a,b,c,\n1,2,3,\n4,5,6"
content_resource = provider.create(data, extension=".csv")
response = requests.get(content_resource.url)
assert response.text == data
assert "text/csv" in response.headers["Content-Type"]
Note: the
Provider
holds a weak reference to each resource it creates. This allows the provider to cleanup unused resources and prevent memory leaks. As an end user, you must hold a strong reference each resource returned by the provider so long as you'd like that endpoint to remain avaiable.
license
servir
is distributed under the terms of the
MIT license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
servir-0.1.1.tar.gz
(11.7 kB
view details)
Built Distribution
servir-0.1.1-py3-none-any.whl
(11.8 kB
view details)
File details
Details for the file servir-0.1.1.tar.gz
.
File metadata
- Download URL: servir-0.1.1.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 858736faa40d22e1ca0a9f52ac69ceea236f503a747ea5f0d7a9f3365a3bacf5 |
|
MD5 | 04eddbe76ce5e7a0b631c85b552cd255 |
|
BLAKE2b-256 | ae08a8bdd7182dfbdaaa3fd990923ad75140220b30469757489bd3fdf6e00b21 |
File details
Details for the file servir-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: servir-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1445555a846faf05cbfeb1a3a3b3de915fdb6fb4774e86840e8c82b1d283c47 |
|
MD5 | 1b10f3cb54fce82df552891d5e241857 |
|
BLAKE2b-256 | 314c8090494565b40aba04642a197f1a859e23383d49988d49f94b32b4bbd261 |