socpi
A simple async socket framework for python supporting tcp and unix sockets. Allows you to go beyond json by using pickle
How to use it
from socpi import App, Client
# create the app with the socket path for unix sockets
app = App('/run/socpi')
# or use [ip, port] tuple for tcp
# app = App(('0.0.0.0', 4238))
# Specify your endpoints
@app.register
def echo(msg: str) -> str:
return msg.lower()
# then launch your server, change `SERVER` to false to launch a client
SERVER = True
if SERVER:
asyncio.run(app.run())
# or launch a client:
async def main():
# no openapi required, everything is generated from the `app`
client = Client(app)
print(await client.echo('fooo'))
if not SERVER:
asyncio.run(main())
There is a demo of a chat application in the examples directory.
What can it do:
Generators:
You can write and call generators and async generators:
@app.register
def foo():
print('hello from the other side')
yield 'foo'
And call them like you would expect:
async for i in client.foo():
print(i)
Every generator will be turned into an async one!
Exceptions:
Exception handling is completely transparent, just raise and except them
as usual.
@app.register
def failer():
raise Exception('foo')
Handle them as usual, the objects will not be changed (but missing server and broken connections will add some extra ones):
try:
await client.failer()
except Exception as e:
print(e) # foo
Serialization:
Anything pickleable will work, as such remote code execution is not a bug,
it is a feature. Deploying socpi to the wider internet is not recommended.
A json only version might be a more secure, less capable option.
Metadata
Release files for socpi 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| socpi-0.2.1.tar.gz | 12.6 kB | Without provenance | Details for socpi-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| socpi-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for socpi-0.2.1-py3-none-any.whl |
Total release size: 26.4 kB
Release files / socpi-0.2.1.tar.gz
| Download URL | socpi-0.2.1.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebded5780220439d3ea09e8f6caf17ae1b6803692afb78342c813faf8388e1e2
|
|
BLAKE2b-256 checksum How to use checksums |
180b2f6518abac81f35430b7bf99e73f695f0316f83421fbee51562f25200b2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.14 CPython/3.10.5 Linux/5.18.12-264-tkg-pds
|
Release files / socpi-0.2.1-py3-none-any.whl
| Download URL | socpi-0.2.1-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce90b7286dca3ea41771a88ac39925f2fa8105e96d3b77716625b456acf116a2
|
|
BLAKE2b-256 checksum How to use checksums |
b67efa39e373e6ec2938138c1eba40f506b74c83a6a4829b24b673544a5606cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.14 CPython/3.10.5 Linux/5.18.12-264-tkg-pds
|
Security for socpi 0.2.1
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.