Skip to main content

Actions Server

A very simple, multi-threaded HTTP server.

Mainly designed for a very simple tasks, f.ex. 3 json-based endpoints with a simple logic

It utilizes a concept of "Actions" - the functions that can be executed to provide HTTP response.

Important note:

This server DOES NOT cover all HTTP functionality. This is intentional and probably will not be changed in the future.

Usage

from actions_server import *

ACTIONS = [
    JsonGet("/get", lambda params: {"response": "ok from GET action"}),
    JsonPost("/post", lambda params, body: {"response": "ok from POST action"}),
    Redirect("/", "/get"),
    StaticResources("/static", "./src/web")
]

server = http_server(port=80, actions=ACTIONS, thread_count=5)

try:
    server.start(block_caller_thread=True)
finally:
    server.stop()

In this example, a server will be started on port 80 and the main thread will be blocked. The server will react on several requests:

  • curl -X GET "http://localhost:80/get" will produce {"response": "ok from GET action"} response
  • curl -X POST "http://localhost:8080/post will produce {"response": "ok from POST action"} response
  • curl -X GET "http://localhost:80/ will send HTTP 301 Redirect to `http://localhost:80/get"
  • curl -X GET "http://localhost:80/static/aaa.png will return an image ./src/web/aaa.png

Actions out-of-the-box

JsonGet(endpoint, callable)

Will listen to the endpoint endpoint, call callable(params) (where params is a dict of arguments; note - values are always an array!) and convert resulting dict into JSON

JsonPost(endpoint, callable, body)

Will listen to the endpoint endpoint, call callable(params, body) (where params is a dict of arguments; note - values are always an array!, and body is a parsed the request body into dict) and convert resulting dict into JSON

Redirect(from, to)

Will send HTTP 301 Redirect

StaticResources(path, dir)

Will server all files from dir under path path

Implementing custom action

from actions_server import *

class MyCustomResponse(Response):
    def __init__(self, payload):
        self._payload = payload

    def headers(self) -> dict:
        return {'Content-type': 'text/plain'}

    def response_body_bytes(self):
        return self._payload.encode('utf-8')

class MyCustomAction(Action):
    def can_handle(self, method, path, params, payload):
        return method == 'GET' and path == '/hello'

    def handle(self, method, path, params, payload) -> Response:
        return MyCustomResponse("hello there!")

Notes:

  • parameter method may contain two strings - GET or POST
  • response body must be bytes!

Metadata

Release files for actions-server 0.0.10

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

Source distribution (sdist)

Source distribution for actions-server 0.0.10
File Size Uploaded Provenance
actions-server-0.0.10.tar.gz 8.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for actions-server 0.0.10
File Interpreter ABI Platform
actions_server-0.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / actions-server-0.0.10.tar.gz

Download URL actions-server-0.0.10.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
183099a85c5c25b12df7ed010d525aa807e48b2117906e67bb226bd080f8a521
BLAKE2b-256 checksum
How to use checksums
c67f7f6a791c62d23c66d94e38a28062aff340543e3348707bb5fae7fb7555c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / actions_server-0.0.10-py3-none-any.whl

Download URL actions_server-0.0.10-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6d62481d02d9a219becf39ee6e305549f0c306e5c0af066026ee14d9f4cb72c
BLAKE2b-256 checksum
How to use checksums
46d4069a0ddfca82c32ae051935b4652d616c146482468e60de1b4ee5a800c67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Security for actions-server 0.0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.10 This release

2 release files No provenance

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