Skip to main content

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

🔧 Configuration

snapserve provides flexible runtime configuration via CLI flags:

snapserve serve calculator:add,subtract \
--host localhost \         # Bind address (default: localhost)
--port 8080 \              # Port (default: 8000)
--workers 4 \              # Worker threads (default: 2 × CPU cores)
--max-concurrency 100 \    # Max concurrent requests
--timeout 30 \             # Request timeout (seconds)
--allow-cache \            # Enable result caching
--cache-size 10000 \       # Cache capacity
--daemon                   # Run as a background daemon

🛠️ 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 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

snapserve-1.2.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snapserve-1.2.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file snapserve-1.2.0.tar.gz.

File metadata

  • Download URL: snapserve-1.2.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for snapserve-1.2.0.tar.gz
Algorithm Hash digest
SHA256 75169e8ecda1e587261b65e5fcf102d4c008f36a35b8559f5e0abe7049aba5a3
MD5 94d3ba6246b1d34f08b4dbdfc2d67df6
BLAKE2b-256 6bc5ed3d073064b8b0ff82318db18ebb9d75ffc2ad69793ded2cb08d90f6cf9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for snapserve-1.2.0.tar.gz:

Publisher: python-publish.yml on panuthept/snapserve

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snapserve-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: snapserve-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for snapserve-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e97f7d64439e45488dc604bc97b528b2b85b153b14d21fdaf0efbdd8145f79ec
MD5 7bf8d597bdcd93756f5f8a3cab21982a
BLAKE2b-256 93737afb8c26bfa68212b147333a5bccac7211435f0772a1fe4e18a9d6de81e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for snapserve-1.2.0-py3-none-any.whl:

Publisher: python-publish.yml on panuthept/snapserve

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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