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)
--cachable \               # Enable result caching
--cache-size 10000         # Cache capacity

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.1.2.tar.gz (12.4 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.1.2-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for snapserve-1.1.2.tar.gz
Algorithm Hash digest
SHA256 9b7e34fd35b84a111511e606ffa55d3cb13e2edb208e78c76a2e9dd32b10c9e8
MD5 cfa20d097ac19d86cc06a001c9a23aa0
BLAKE2b-256 a3ba957241886aa00894f4e96d397132b894683dccc28c97a1e7f07fb080f700

See more details on using hashes here.

Provenance

The following attestation bundles were made for snapserve-1.1.2.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.1.2-py3-none-any.whl.

File metadata

  • Download URL: snapserve-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.3 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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 068af3454ab9a47fe2b97df30d2e4c09c6166ff04bf99dfecea4bbbd7d1cee2f
MD5 6d53e82e3c8be6f1c24ba343e0ac9a2e
BLAKE2b-256 fa2f71f7177f355d69735ad63a552a976e7714041194ed7be73d20a1ac3a0482

See more details on using hashes here.

Provenance

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