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.0.6.tar.gz
(11.5 kB
view details)
Built Distribution
servir-0.0.6-py3-none-any.whl
(11.6 kB
view details)
File details
Details for the file servir-0.0.6.tar.gz
.
File metadata
- Download URL: servir-0.0.6.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1876284b447b83d528ceb3d13ca7aba798dda5316a4a9f4004a912371257a21 |
|
MD5 | 908ea908437a175d2e5fa73f7eea7f09 |
|
BLAKE2b-256 | c580e85a3b992f7d9383bf3663562c232a4639fab21082a9f0b24a0b7a3e0aa5 |
File details
Details for the file servir-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: servir-0.0.6-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1cb91bc30625004bd748fa9e1e57c77882076341d8790393e5fac4fd08aba67 |
|
MD5 | 03b590a33e7e2d4ad96337b4aa14670b |
|
BLAKE2b-256 | af1471a83a04bc3f320e41f8ed217813735dd94525b4bcb836ac1a2d76e60424 |