Skip to main content

socketsundso

Warning: This project is in very early development.

What's all this then?

This is an opionated framework for creating WebSocket APIs based on FastAPI, Starlette and pydantic. FastAPI offers nice validation (powered by pydantic) for HTTP endpoints. This framework tries to make it easy to use all these goodies when develooping a JSON based websocket API.

Concept

The whole idea is based around the concept of a simple json based protocol. Messages between client and server can be categorized by a type or event and contain some data. For HTTP the type/event will mostly be conveyed via path or querystring. When using WebSockets you could also use the path for this but this would mean opening a new socket for every type of event. Seems unnecassery when you already have a perfectly working connection established.

Message Format

The basic message format is as follows

{
	type: str,
	...
}

Seems simple. Doesn't it? Well here comes the magic: Let's assume we want to build something similar to a chat application where users can send messages. So we would have an event called message. In our application we can simply define a handler for it and this awesome framework will call the handler whenever it receives a message with the type 'message'.

@on_event
def on_message(self, message: str) -> None:
	print('Hey i just received a message:')
	print(message)

When registering a handler like above, socketsundso will create a pydantic model specifically for messages for this handler. This model is similar to this:

class Message(BaseModel):
	type: typing.Literal('message'),
	message: str

	class Config:
		extra = 'forbid'

The response will also be validated through a model. But since it's hard to guess what you want in your output you have to give a response_model. Otherwise socketsundso will just make sure there is a type in the response. For more information take a look at the documentation.

Documentation

The documentation is located at https://socketsundso.dingensundso.de. You can also find some examples in examples/

Roadmap

Things that should/will/propably won't be implemented soon:

  • validation of incoming data (based on type signatures of handlers)
  • tests!!!
  • response_model
  • don't require handlers to be async
  • nice and shiny documentation
  • more and better examples
  • some crazy scheme to make money with this (maybe add a cryptominer to some file deep within?)
  • some kind of license
  • make it compatible with older python versions (at least 3.9, maybe even 3.7)
  • more and better tests
  • more and better documentation

Metadata

Release files for socketsundso 0.0.5

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

Source distribution (sdist)

Source distribution for socketsundso 0.0.5
File Size Uploaded Provenance Actions
socketsundso-0.0.5.tar.gz 17.9 kB Without provenance Details for socketsundso-0.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for socketsundso 0.0.5
File Interpreter ABI Platform Actions
socketsundso-0.0.5-py3-none-any.whl Python 3 none any Details for socketsundso-0.0.5-py3-none-any.whl

Total release size: 28.1 kB

Release files / socketsundso-0.0.5.tar.gz

Download URL socketsundso-0.0.5.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b088152cd0b8ade43b99e63257cd41e8798f165fec9b2375a4065517117f9fdf
BLAKE2b-256 checksum
How to use checksums
62688260c021d5aae126a8dadc78440705f73cf8dd31e31d44e2b507edc980ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.27.1

Release files / socketsundso-0.0.5-py3-none-any.whl

Download URL socketsundso-0.0.5-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f1f24a2a0e10565066859128dcca3b0f6219a467503acc8e8241edb4fb62e41
BLAKE2b-256 checksum
How to use checksums
67f422ffb3d33b217c0d32e47e158a88a924a6551c0cd8409ee212a6a8a1426a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.27.1

Security for socketsundso 0.0.5

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.

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