Turn your Python functions, classes, and objects into remote services instantly.
Project description
SnapServe
Turn your Python functions, classes, and objects into remote services instantly.
SnapServe is a lightweight framework that exposes your Python code as a remote service with a single command. It lets you serve functions, classes, or stateful objects without writing any API boilerplate, and interact with them through a simple Python client.
Instead of building and maintaining server code (e.g., with FastAPI or Flask), you focus on your application logic, SnapServe handles the serving layer and execution for you.
📦 Install
pip install snapserve
🚀 Quick Start
🔹 Serve Functions
Expose one or more functions with a single command:
# calculator.py
def add(a: float, b: float) -> float:
return a + b
def subtract(a: float, b: float) -> float:
return a - b
snapserve serve calculator:add,subtract
🌐 SnapServe is live:
(function) add(a: float, b: float) -> float
(function) subtract(a: float, b: float) -> float
Call them from Python:
from snapserve import remote
add = remote("add")
subtract = remote("subtract")
print(add(5, 3)) # → 8
print(subtract(5, 3)) # → 2
SnapServe supports multiple Python abstractions with a unified interface.
🔹 Serve Classes
Serve a class definition. Each call creates a new isolated instance on the server.
# calculator_class.py
class Calculator:
def add(self, a: float, b: float) -> float:
return a + b
def subtract(self, a: float, b: float) -> float:
return a - b
snapserve serve calculator_class:Calculator
from snapserve import remote
Calculator = remote("Calculator")
calc = Calculator()
print(calc.add(5, 3)) # → 8
print(calc.subtract(5, 3)) # → 2
🔹 Serve Objects (Stateful)
Serve an existing object to preserve state across calls.
# calculator_class.py
class Calculator:
def __init__(self):
self.last_result = None
def add(self, a: float, b: float) -> float:
self.last_result = a + b
return self.last_result
def subtract(self, a: float, b: float) -> float:
self.last_result = a - b
return self.last_result
calc = Calculator()
snapserve serve calculator_class:calc
from snapserve import remote
calc = remote("calc")
print(calc.add(5, 3)) # → 8
print(calc.last_result) # → 8
print(calc.subtract(5, 3)) # → 2
print(calc.last_result) # → 2
🛠️ CLI Commands
Serve Python functions, classes, and objects as an API.
Usage: snapserve serve [OPTIONS] MODULE_PATH
Arguments:
MODULE_PATH The module path to serve, in the format 'module_path:variable_name'.
Options:
--host STRING The host to bind the server to. [default: localhost]
--port INTEGER The port to bind the server to. [default: 8000]
--workers INTEGER The number of worker threads to handle requests. [default: 2 × CPU cores]
--max-concurrency INTEGER The maximum number of concurrent requests the server can handle. [default: 100]
--timeout INTEGER The request timeout in seconds. [default: 30]
--allow-cache Enable caching of function results to improve performance for repeated calls with the same arguments.
--cache-size INTEGER The maximum number of entries to store in the cache. [default: 10000]
--daemon Run the server as a background daemon process.
List all running snapserve servers.
Usage: snapserve ps
Stop a running snapserve server.
Usage: snapserve stop [OPTIONS] SERVER_ID
Arguments:
SERVER_ID The ID of the server to stop.
Options:
--all Stop all running servers.
--delete Delete the server after stopping it.
Start a stopped snapserve server.
Usage: snapserve start [OPTIONS] SERVER_ID
Arguments:
SERVER_ID The ID of the server to start.
Options:
--host STRING The host to bind the server to.
--port INTEGER The port to bind the server to.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snapserve-1.2.1.tar.gz.
File metadata
- Download URL: snapserve-1.2.1.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
783940aa7329cd1b5a3da08bc912b0baa696232403cdc5acbcda0777d37cd3c9
|
|
| MD5 |
a361e301f01b860037c95bce3e86ec57
|
|
| BLAKE2b-256 |
14f543cd48f3cc59a55276b24a649e66204f0a9b0a3e0e164de10912e871edd6
|
Provenance
The following attestation bundles were made for snapserve-1.2.1.tar.gz:
Publisher:
python-publish.yml on panuthept/snapserve
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
snapserve-1.2.1.tar.gz -
Subject digest:
783940aa7329cd1b5a3da08bc912b0baa696232403cdc5acbcda0777d37cd3c9 - Sigstore transparency entry: 1310036560
- Sigstore integration time:
-
Permalink:
panuthept/snapserve@8fce2e97c5793d591fc3ee78e8d9e897425aae22 -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/panuthept
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8fce2e97c5793d591fc3ee78e8d9e897425aae22 -
Trigger Event:
release
-
Statement type:
File details
Details for the file snapserve-1.2.1-py3-none-any.whl.
File metadata
- Download URL: snapserve-1.2.1-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c22b7b287ba55c4d8c17c7077041f70b109f14e19baa08f2e7b7cb96d0f68b2
|
|
| MD5 |
1bbdc62eaea499321506c9e47e303a5f
|
|
| BLAKE2b-256 |
f074e478a16b14277d48d4d9c531c427a2452ca314c479afdebeb060a5c412e9
|
Provenance
The following attestation bundles were made for snapserve-1.2.1-py3-none-any.whl:
Publisher:
python-publish.yml on panuthept/snapserve
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
snapserve-1.2.1-py3-none-any.whl -
Subject digest:
0c22b7b287ba55c4d8c17c7077041f70b109f14e19baa08f2e7b7cb96d0f68b2 - Sigstore transparency entry: 1310036621
- Sigstore integration time:
-
Permalink:
panuthept/snapserve@8fce2e97c5793d591fc3ee78e8d9e897425aae22 -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/panuthept
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8fce2e97c5793d591fc3ee78e8d9e897425aae22 -
Trigger Event:
release
-
Statement type: