Skip to main content

an extensible async background server

Project description

servir

PyPI - Version PyPI - Python Version

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.2.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

servir-0.2.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file servir-0.2.0.tar.gz.

File metadata

  • Download URL: servir-0.2.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for servir-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dcc54ed7f7a02adea987fb0c78c644d1bdd96bcfb55dfde8d970cdc9a56b2489
MD5 402e75ca40e9158561286fa29d701150
BLAKE2b-256 912d8c3a7d43ce24bc6c5a3456fc94f3a08f329a567e5d7f74a201d5be272c48

See more details on using hashes here.

File details

Details for the file servir-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: servir-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for servir-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ebc84b76544c7faea9a83f03e16de505e6e1641424adb68ee14f3c26895fb7d
MD5 4e4b7a6e67eb69bca431e503548db47a
BLAKE2b-256 b531fe76ef553c20f324a387140a026813378f8cb4d02236c5f78730ed3371a6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page