Skip to main content

A simple framework for building SDCP servers

Project description

SDCP

A simple Python framework for building SDCP (Secure Data Communication Protocol) servers, inspired by Flask.

Installation

pip install sdcp

Requirements

You need a running SDCP main authentication server. Each server must have a server_keys.json file containing its pre-shared key with the main server.

Quick Start

from sdcp import SDCP, Request, Response, html

app = SDCP(
    server_keys_file="server_keys.json",
    server_id="server_1",
    main_server_host="127.0.0.1",
    main_server_port=300,
)

@app.route("/")
def index(request: Request) -> Response:
    return html("<head><title>Home</title></head><body><h1>Hello!</h1></body>")

@app.route("/about")
def about(request: Request) -> Response:
    return html("<head><title>About</title></head><body><h1>About</h1></body>")

@app.not_found
def not_found(request: Request) -> Response:
    return html(f"<h1>404 - {request.path} not found</h1>")

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=299, debug=True)

API Reference

SDCP(server_keys_file, server_id, main_server_host, main_server_port)

Creates an SDCP app instance.

Parameter Default Description
server_keys_file "server_keys.json" Path to JSON file containing this server's PSK
server_id "server_1" This server's ID, must match the key in server_keys_file
main_server_host "127.0.0.1" Hostname of the main auth server
main_server_port 300 Port of the main auth server

@app.route(path)

Registers a handler for a given path. Use * at the end for wildcard matching.

@app.route("/blog/*")
def blog(request: Request) -> Response:
    return html(f"<h1>Blog post: {request.path}</h1>")

@app.not_found

Registers a custom 404 handler.

Request

Attribute Description
request.path The path requested by the client
request.client_id The authenticated client's ID

html(content)

Helper to return an HTML response.

app.run(host, port, debug)

Starts the server.

Parameter Default Description
host "0.0.0.0" Interface to bind to
port 299 Port to listen on
debug False Print connection logs

server_keys.json format

{
  "server_1": "<base64url-encoded-key>"
}

Generate this using the SDCP add_server tool.

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

sdcp-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sdcp-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file sdcp-0.1.0.tar.gz.

File metadata

  • Download URL: sdcp-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for sdcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 108e25a53dda684a7f6fe1ae09fb67d190342f2dd6af98702d4eb850589cd93a
MD5 632d00b93d02a036e18543501fa36217
BLAKE2b-256 e62bc0dabfc3abc389e6bf0cb2bf5a7587ed7ec5780d66c6fa48470f45941fbd

See more details on using hashes here.

File details

Details for the file sdcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sdcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for sdcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3dcce59d9734e4d4e2ac19954c7ba7ce9045bd9b20115c3800af6e57a2e9c3a3
MD5 2cc199ddc05d2318452e0a489ccca179
BLAKE2b-256 ac095439f7d743e1df49b6dfc9fdc9b8e95816af3e70367d830df95b284170dd

See more details on using hashes here.

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