Skip to main content

sw-serverless

Write SW-Serverless adapters in Python 3.12 or later. The package has no dependencies: it speaks the host's protocol — gRPC over a Unix socket — with the standard library alone, so it vendors into an adapter package as plain files, for any platform.

import sw_serverless as sw


class Greeter:
    def __init__(self):
        sw.expect("Greeting", "Hello", description="What to say")
        sw.expect("ApiKey", secret=True)

    @sw.command(description="Greets someone")
    def greet(self, name: str) -> str:
        return f"{sw.value_of('Greeting')}, {name}"


if __name__ == "__main__":
    sw.run(Greeter)
  • Settings are declared with sw.expect(name, default=None, *, required, secret, description, type) and read with sw.value_of(name): the call's own properties, then the values the adapter was started with, then the default.
  • Commands are methods marked @sw.command(name, description=...). A command takes at most one argument. A str argument or result is raw text, bytes are passed as they are, and anything else is JSON; a dataclass is read from and written as a JSON object. Commands may be sync or async; sync ones run on a worker thread.
  • Errors raised by a command reach the caller with their type and message. Raise sw.AdapterError(message, type="Acme.Rejected") to choose the type.
  • Resident adapters have a start method and run until stopped, with optional stop, status (returns connected, state, details…) and reset(session_id). In a command, sw.context() publishes events (await ctx.publish(...)), keeps small state (get_state/set_state/delete_state) and records metrics.
  • Logging through Python's logging reaches the host.
  • python main.py --describe prints what the adapter is; sw-serverless build writes it into the manifest.

An application with a contract of its own declares it with @sw.implements("orders", 1, "processor") on the adapter class, and can give its adapter authors base classes that do it for them. sw-serverless init --lang python starts an adapter.

Tests: PYTHONPATH=src python -m unittest discover -s tests.

Metadata

Release files for sw-serverless 10.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sw-serverless 10.2.3
File Size Uploaded
sw_serverless-10.2.3.tar.gz 25.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sw-serverless 10.2.3
File Interpreter ABI Platform
sw_serverless-10.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 48.9 kB

Release files / sw_serverless-10.2.3.tar.gz

Download URL sw_serverless-10.2.3.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
84b63d8eae199375336d149070ac12c53fb0c7b2d410646cd619083cdd7ce2f8
BLAKE2b-256 checksum
How to use checksums
7b49566c87045fb2e1c42a141252fde85a7749a1f91831891c6063e3cdc70a1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / sw_serverless-10.2.3-py3-none-any.whl

Download URL sw_serverless-10.2.3-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9df5e8ccb35459c77c6739e11867eebc4f621881001e9a312daaa7bc7d09cdc4
BLAKE2b-256 checksum
How to use checksums
a4b6f7b8e61d0f34d05e0bf98bf71e395d1693d2488c53b121c2afc289b43d2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

10.2.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page