Skip to main content

No project description provided

Project description

SnapServe

Turn your Python functions, classes, and objects into callable services instantly.

SnapServe is a lightweight framework that exposes your Python code as a local 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.0.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.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snapserve-1.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 593aced62a6d28dc4c534f706f1c1655acae046a89bcc9cad6975495416c8bad
MD5 f7add9d9b2b92e902f696399b2e1ac5a
BLAKE2b-256 0b3696f0941e5b58c35cc6ffcab7daa2153e1a0372f2da4eaf19981b363ac6e0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: snapserve-1.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebe13a3d793cd6289ef8ca2ceaa571c3448e3e3cfcf88c81c513875083398f57
MD5 844c63abf9689748c780491ed3b808b2
BLAKE2b-256 485ef2cd2b086fee3ee49758dabd891490578cb146122584bda2809c83a97f0b

See more details on using hashes here.

Provenance

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