Trinket
A Curio HTTP server.
Installation
Trinket requires python3.7+
git clone https://github.com/trollfot/trinket.git
python3.7 -m venv trinket_env
source trinket_env/bin/activate
pip install -e trinket trinket[test]
pytest trinket/tests
Example
from trinket import Trinket, Response
from trinket.response import file_iterator
from trinket.extensions import logger
bauble = logger(Trinket())
@bauble.route('/')
async def hello(request):
return Response.raw(b'Hello World !')
@bauble.route('/raw', methods=['POST'])
async def raw(request):
return Response.raw(b'You got here')
@bauble.route('/read', methods=['POST'])
async def reader(request):
await request.parse_body()
files = list(request.files.keys())
return Response.raw("You got here and it's all read: {}".format(files))
@bauble.route('/hello/full/with/{one}/and/{two}')
async def json(request, one, two):
response = Response.json({
'parameters': f'{one} and {two}',
'query': request.query.get('query'),
'cookie': request.cookies['test'],
})
response.cookies.set(name='bench', value='value')
return response
@bauble.route('/websocket')
async def serve_websocket(request):
response = Response.streamer(file_iterator('myfile.ext'))
return response
@bauble.websocket('/chat')
async def chat(request, websocket):
while True:
msg = await websocket.recv()
for ws in bauble.websockets:
if ws is not websocket:
await ws.send(msg)
bauble.start()
Acknowledgments
Trinket relies heavily on packages from https://github.com/pyrates: very good re-useable components with Cython-improved performances.
Changelog
0.1.5 (2019-12-18)
Fixed body duplication on raw_body calls, due to the concatenation already happening in on_body, triggered by the reader.
0.1.4 (2019-12-16)
Dependencies maintenance : bumping versions to latest stable.
0.1.3 (2019-01-24)
Pinned specific package versions
Updated to use the last version of wsproto (0.13)
The Trinket application now inherits from dict to allow arbitrary storage
Decoupled the TCP serving/socket creation from the actual application
0.1.2 (2019-01-18)
Updated distribution files
0.1.1 (2019-01-18)
Added tests and testing utilities
Fixed missing imports
0.1 (2019-01-17)
Initial release
Metadata
Release files for trinket 0.1.5
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 |
|---|---|---|---|---|
| trinket-0.1.5.tar.gz | 19.4 kB | Without provenance | Details for trinket-0.1.5.tar.gz |
Release files / trinket-0.1.5.tar.gz
| Download URL | trinket-0.1.5.tar.gz |
|---|---|
| Size | 19.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f66064d5c1af2350ff9643540f7a74eb0fd02198d101ce8aa97f296c868a342
|
|
BLAKE2b-256 checksum How to use checksums |
1da50cad5f1db6ad37455d9e9d8f5a07e1fdc993da607dd14a81492d5ddf6cc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Security for trinket 0.1.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.