Python serverless framework for Datastone Spirit GPU.
Project description
Spirit-GPU
Install
pip install spirit-gpu
Usage example
from spirit_gpu import start
from spirit_gpu.env import Env
def handler(request: Dict[str, Any], env: Env):
"""
request: Dict[str, Any], from client http request body.
request["input"]: Required.
request["webhook"]: Optional string for asynchronous requests.
returned object to be serialized into JSON and sent to the client.
in this case: '{"output": "hello"}'
"""
return {"output": "hello"}
def gen_handler(request: Dict[str, Any], env: Env):
"""
append yield output to array, serialize into JSON and send to client.
in this case: [0, 1, 2, 3, 4]
"""
for i in range(5):
yield i
async def async_handler(request: Dict[str, Any], env: Env):
"""
returned object to be serialized into JSON and sent to the client.
"""
return {"output": "hello"}
async def async_gen_handler(request: Dict[str, Any], env: Env):
"""
append yield output to array, serialize into JSON and send to client.
"""
for i in range(10):
yield i
def concurrency_modifier(current_allowed_concurrency: int) -> int:
"""
Adjusts the allowed concurrency level based on the current state.
For example, if the current allowed concurrency is 3 and resources are sufficient,
it can be increased to 5, allowing 5 tasks to run concurrently.
"""
allowed_concurrency = ...
return allowed_concurrency
"""
Register the handler with serverless.start().
Handlers can be synchronous, asynchronous, generators, or asynchronous generators.
"""
start({
"handler": async_handler, "concurrency_modifier": concurrency_modifier
})
API
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
spirit_gpu-0.0.3.tar.gz
(17.0 kB
view hashes)
Built Distribution
spirit_gpu-0.0.3-py3-none-any.whl
(14.0 kB
view hashes)
Close
Hashes for spirit_gpu-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e18611be9153a5e3c3d2cd2517aab0e4403f8f68594bbe269a21d54cddfa664 |
|
MD5 | d77858598e97ac2173302e5c0e78cab0 |
|
BLAKE2b-256 | 423ab56f21bc59775af4615c3a541cfd48a6a526738138a4435f335940db1ff5 |