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

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

snapserve-1.2.1.tar.gz (15.5 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.1-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

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

Hashes for snapserve-1.2.1.tar.gz
Algorithm Hash digest
SHA256 783940aa7329cd1b5a3da08bc912b0baa696232403cdc5acbcda0777d37cd3c9
MD5 a361e301f01b860037c95bce3e86ec57
BLAKE2b-256 14f543cd48f3cc59a55276b24a649e66204f0a9b0a3e0e164de10912e871edd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for snapserve-1.2.1.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.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

Hashes for snapserve-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c22b7b287ba55c4d8c17c7077041f70b109f14e19baa08f2e7b7cb96d0f68b2
MD5 1bbdc62eaea499321506c9e47e303a5f
BLAKE2b-256 f074e478a16b14277d48d4d9c531c427a2452ca314c479afdebeb060a5c412e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for snapserve-1.2.1-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