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 withsw.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. Astrargument or result is raw text,bytesare 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
startmethod and run until stopped, with optionalstop,status(returnsconnected,state,details…) andreset(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
loggingreaches the host. python main.py --describeprints what the adapter is;sw-serverless buildwrites 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)
| File | Size | Uploaded | |
|---|---|---|---|
| sw_serverless-10.2.3.tar.gz | 25.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|