My simple async web framework
Project description
Webpet
Simple async web framework for python
This is my pet project and it doesn't pretend to be serious
Links
Simple Usage example
from webpet.application import ASGIApplication
from webpet.conf import Configuration
from webpet.response import HTTPResponse
from webpet.routers import HTTPRouter, URL
from webpet.views import View, LongPoolView, TemplateView
import asyncio
import json
import random
import os
BASE_DIR = os.getcwd() + '/'
class Index(TemplateView):
template_name = 'index.html'
class Aboba(View):
async def get(self):
raise ValueError()
class TestLong(LongPoolView):
async def get(self):
await self.open(status_code=200, headers=[(b'Content-type', b'application/json')])
data = []
ticks = 0
while True:
ticks += 1
number = random.randint(0, 1000)
data.append(number)
if number >= 500:
await self.send(HTTPResponse(
json.dumps({
'data': data,
'ticks': ticks
})
))
break
else:
await asyncio.sleep(1)
router = HTTPRouter(routes=[
URL('/', Index),
URL('/aboba', Aboba),
URL('/longpool', TestLong)
])
configuration = Configuration()
configuration.router = router
configuration.templates_dir = BASE_DIR + 'templates/'
app = ASGIApplication()
To run with daphne use
pip install daphne
daphne <application_name>:<ASGIApplication instance>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
webpet-0.1.1.tar.gz
(3.5 kB
view details)
Built Distribution
File details
Details for the file webpet-0.1.1.tar.gz
.
File metadata
- Download URL: webpet-0.1.1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5655dda7fc4aabbe7aba61b6ad2fd72cb00a8aeb67c731b0924965ec385daaf |
|
MD5 | 8b516b2d506a595d74a4226f2e227dd3 |
|
BLAKE2b-256 | 8facf510308d72ce0c9eb9ca876fe61ff127436517ba668ed97d501a88373a02 |
File details
Details for the file webpet-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: webpet-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4302a46b8a26c5a31cbcfe6a8831530a08c7dbe8e5a775ccd12f4ed2659e6854 |
|
MD5 | 8b4583c2e382f5b3ff2ecce28c43322f |
|
BLAKE2b-256 | 78b6df30e9a1432494c019dcf1b7cabeb09f717bc92a37ebd358c56a6a8c8fad |