Turn your Python functions, classes, objects, and variables into remotely accessible artifacts with zero boilerplate.
Project description
SnapServe
Turn your Python functions, classes, objects, and variables into remotely accessible artifacts with zero boilerplate.
SnapServe is a lightweight library for exposing Python functions, classes, objects, and variables as remotely accessible artifacts in a single command line of code without writing API boilerplate. Whether you want to build a simple microservice, share a machine learning model, or provide a remote interface to your Python code, SnapServe makes it easy to expose and use Python functionality over the network.
📦 Install
pip install snapserve
🚀 Quick Start
Define your Python artifacts
Create a file with anything you want to expose: functions, classes, objects, or variables:
# calculator.py
def add(a: float, b: float) -> float:
return a + b
class Calculator:
def __init__(self, bias: float = 0.0):
self.bias = bias
def multiply(self, a: float, b: float) -> float:
return a * b + self.bias
calc = Calculator(bias=2.0)
z = 10
Serve them without messing with API boilerplate
Expose anything with a single command:
snapserve serve calculator \
--expose add,Calculator,calc,z \ # List of artifacts to expose (comma-separated)
--host localhost \
--port 8000
Use them remotely
Connect from any Python script:
from snapserve import Remote
with Remote("http://localhost:8000") as remote:
# 🔹 Functions: Call remote functions like local ones
result = remote.add(5, 3)
print(result) # → 8
# 🔹 Classes: Instantiate and use remote classes
calc = remote.Calculator(bias=1.0) # Instantiate with custom arguments
result = calc.multiply(5, 3)
print(result) # → 16 (5 * 3 + 1.0)
# 🔹 Objects: Use pre-initialized remote objects
result = remote.calc.multiply(5, 3)
print(result) # → 17 (5 * 3 + 2.0)
# 🔹 Variables: Access shared variables directly
print(remote.z) # → 10
remote.z = 20 # Remote variable can be updated and will reflect across all clients
remote.z += 10 # Remote variable can be updated with operations
print(remote.z) # → 30
# After the with block, the instantiated objects created on the server will be automatically cleaned up.
🛠️ CLI Commands
Serve Python functions, classes, objects, and variables as an API.
Usage: snapserve serve [OPTIONS] MODULE_PATH
Arguments:
MODULE_PATH The module path to serve.
Options:
--expose STRING Comma-separated list of artifacts to expose (functions, classes, objects, variables).
--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.3.0.tar.gz.
File metadata
- Download URL: snapserve-1.3.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f712de314b1854a4661ae048bce97965a9caa3bc3185139850184abd374398d5
|
|
| MD5 |
e30ce922555ea16c34ad007d4d44e932
|
|
| BLAKE2b-256 |
6e105ec958223fa3a6d3e5984798c27bc6f4f14552103e3e7f8dd93eeeccc2b8
|
Provenance
The following attestation bundles were made for snapserve-1.3.0.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.3.0.tar.gz -
Subject digest:
f712de314b1854a4661ae048bce97965a9caa3bc3185139850184abd374398d5 - Sigstore transparency entry: 1356817639
- Sigstore integration time:
-
Permalink:
panuthept/snapserve@2998c7c822d948e7c82153a11196062332e83af6 -
Branch / Tag:
refs/tags/v1.3.0 - Owner: https://github.com/panuthept
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@2998c7c822d948e7c82153a11196062332e83af6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file snapserve-1.3.0-py3-none-any.whl.
File metadata
- Download URL: snapserve-1.3.0-py3-none-any.whl
- Upload date:
- Size: 19.7 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 |
193403d77702055c87c2778e4cdbd77a0e8a4439dd43061f2cb33105b38afeb7
|
|
| MD5 |
316ffdf16f94a32498dae2cd9fe51c22
|
|
| BLAKE2b-256 |
5ddaa192355091c93e672905c4a55400302d2d341c360bbb1ad3bb1580a0bca4
|
Provenance
The following attestation bundles were made for snapserve-1.3.0-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.3.0-py3-none-any.whl -
Subject digest:
193403d77702055c87c2778e4cdbd77a0e8a4439dd43061f2cb33105b38afeb7 - Sigstore transparency entry: 1356817649
- Sigstore integration time:
-
Permalink:
panuthept/snapserve@2998c7c822d948e7c82153a11196062332e83af6 -
Branch / Tag:
refs/tags/v1.3.0 - Owner: https://github.com/panuthept
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@2998c7c822d948e7c82153a11196062332e83af6 -
Trigger Event:
release
-
Statement type: