from apistar.backends import sqlalchemy_backend from apistar.frameworks.asyncio import ASyncIOApp as App from shrim._sqlalchemy_base import Base from shrim.routes import routes settings = {"DATABASE": {"URL": "sqlite:///db.db", "METADATA": Base.metadata}} app = App(routes=routes, settings=settings, commands=sqlalchemy_backend.commands, components=sqlalchemy_backend.components)
import asyncio import logging import uvloop from apistar import Route # from apistar.frameworks.wsgi import WSGIApp as App from apistar.frameworks.asyncio import ASyncIOApp as App asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) logging.getLogger('asyncio').setLevel(logging.CRITICAL) async def minimal(): return {'message': 'Hello, World!'} routes = [ Route('/hello/minimal', 'GET', minimal), ] app = App(routes=routes)
async def list_songs(session: Session): queryset = session.Song.objects.all() return [ {'id': song.id, 'title': song.title, 'track': song.track} for song in queryset ] routes = [ Route('/', 'GET', welcome), Route('/albums/', 'GET', list_albums), Route('/albums/', 'POST', create_album), Route('/songs/', 'GET', list_songs), Route('/songs/', 'POST', create_song), Include('/docs', docs_urls), Include('/static', static_urls) ] app = App( routes=routes, settings=settings, commands=django_orm.commands, components=django_orm.components ) if __name__ == '__main__': app.main()
from backends import redis, asyncpg import slackbot logging.basicConfig( level=(settings.get('DEBUG') and logging.DEBUG) or logging.INFO) logger = logging.getLogger() routes = [ Include('', slackbot.routes), Include('/static', static_urls), Include('/docs', docs_urls), ] components = redis.components + asyncpg.components + slackbot.components + client.components # In DEBUG/DEV environment dump more info to the console/logger if settings.get('DEBUG'): logger.debug("Running in debug/development mode!!!") print_routes(routes) print_settings(settings) print_components(components) logger.debug("Building app now...") app = App(routes=routes, settings=settings, components=components, commands=redis.commands + asyncpg.commands) if __name__ == '__main__': app.main()