All Projects → encode → Starlette

encode / Starlette

Licence: bsd-3-clause
The little ASGI framework that shines. 🌟

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Starlette

Uvicorn Gunicorn Starlette Docker
Docker image with Uvicorn managed by Gunicorn for high-performance Starlette web applications in Python 3.7 and 3.6 with performance auto-tuning. Optionally with Alpine Linux.
Stars: ✭ 92 (-98.55%)
Mutual labels:  graphql, async, websockets
Graphqlws
Implementation of the GraphQL over WebSocket protocol in Go.
Stars: ✭ 139 (-97.81%)
Mutual labels:  graphql, websockets
Snug
Write reusable web API interactions
Stars: ✭ 108 (-98.3%)
Mutual labels:  graphql, async
Microwebsrv2
The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
Stars: ✭ 295 (-95.34%)
Mutual labels:  async, websockets
Turbulette
😴 Turbulette - A batteries-included framework to build high performance, fully async GraphQL APIs
Stars: ✭ 29 (-99.54%)
Mutual labels:  graphql, async
Siler
⚡ Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.
Stars: ✭ 1,056 (-83.34%)
Mutual labels:  graphql, websockets
Aiowebsocket
Async WebSocket Client. Advantage: Flexible Lighter and Faster
Stars: ✭ 263 (-95.85%)
Mutual labels:  async, websockets
Actix Web
Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
Stars: ✭ 12,723 (+100.77%)
Mutual labels:  async, websockets
React Query
⚛️ Hooks for fetching, caching and updating asynchronous data in React
Stars: ✭ 24,427 (+285.47%)
Mutual labels:  graphql, async
Ntex
framework for composable networking services
Stars: ✭ 381 (-93.99%)
Mutual labels:  async, websockets
Graphql Ws
Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client.
Stars: ✭ 398 (-93.72%)
Mutual labels:  graphql, websockets
Brayns
Visualizer for large-scale and interactive ray-tracing of neurons
Stars: ✭ 232 (-96.34%)
Mutual labels:  async, websockets
Async Tungstenite
Async binding for Tungstenite, the Lightweight stream-based WebSocket implementation
Stars: ✭ 207 (-96.73%)
Mutual labels:  async, websockets
Swell
Swell: API development tool that enables developers to test endpoints served over streaming technologies including Server-Sent Events (SSE), WebSockets, HTTP2, GraphQL, and gRPC.
Stars: ✭ 517 (-91.84%)
Mutual labels:  graphql, websockets
Http Kit
http-kit is a minimalist, event-driven, high-performance Clojure HTTP server/client library with WebSocket and asynchronous support
Stars: ✭ 2,234 (-64.75%)
Mutual labels:  async, websockets
Djangochannelsgraphqlws
Django Channels based WebSocket GraphQL server with Graphene-like subscriptions
Stars: ✭ 203 (-96.8%)
Mutual labels:  graphql, websockets
Websocket Client
Async WebSocket client for PHP based on Amp.
Stars: ✭ 83 (-98.69%)
Mutual labels:  async, websockets
Sente
Realtime web comms for Clojure/Script
Stars: ✭ 1,626 (-74.34%)
Mutual labels:  async, websockets
Aws Lambda Graphql
Use AWS Lambda + AWS API Gateway v2 for GraphQL subscriptions over WebSocket and AWS API Gateway v1 for HTTP
Stars: ✭ 313 (-95.06%)
Mutual labels:  graphql, websockets
Pawl
Asynchronous WebSocket client
Stars: ✭ 448 (-92.93%)
Mutual labels:  async, websockets

starlette

The little ASGI framework that shines.

Build Status Package version


Documentation: https://www.starlette.io/


Starlette

Starlette is a lightweight ASGI framework/toolkit, which is ideal for building high performance async services.

It is production-ready, and gives you the following:

  • Seriously impressive performance.
  • WebSocket support.
  • In-process background tasks.
  • Startup and shutdown events.
  • Test client built on requests.
  • CORS, GZip, Static Files, Streaming responses.
  • Session and Cookie support.
  • 100% test coverage.
  • 100% type annotated codebase.
  • Few hard dependencies.
  • Compatible with asyncio and trio backends.

Requirements

Python 3.6+

Installation

$ pip3 install starlette

You'll also want to install an ASGI server, such as uvicorn, daphne, or hypercorn.

$ pip3 install uvicorn

Example

example.py:

from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route


async def homepage(request):
    return JSONResponse({'hello': 'world'})

routes = [
    Route("/", endpoint=homepage)
]

app = Starlette(debug=True, routes=routes)

Then run the application using Uvicorn:

$ uvicorn example:app

For a more complete example, see encode/starlette-example.

Dependencies

Starlette only requires anyio, and the following are optional:

  • requests - Required if you want to use the TestClient.
  • jinja2 - Required if you want to use Jinja2Templates.
  • python-multipart - Required if you want to support form parsing, with request.form().
  • itsdangerous - Required for SessionMiddleware support.
  • pyyaml - Required for SchemaGenerator support.

You can install all of these with pip3 install starlette[full].

Framework or Toolkit

Starlette is designed to be used either as a complete framework, or as an ASGI toolkit. You can use any of its components independently.

from starlette.responses import PlainTextResponse


async def app(scope, receive, send):
    assert scope['type'] == 'http'
    response = PlainTextResponse('Hello, world!')
    await response(scope, receive, send)

Run the app application in example.py:

$ uvicorn example:app
INFO: Started server process [11509]
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

Run uvicorn with --reload to enable auto-reloading on code changes.

Modularity

The modularity that Starlette is designed on promotes building re-usable components that can be shared between any ASGI framework. This should enable an ecosystem of shared middleware and mountable applications.

The clean API separation also means it's easier to understand each component in isolation.

Performance

Independent TechEmpower benchmarks show Starlette applications running under Uvicorn as one of the fastest Python frameworks available. (*)

For high throughput loads you should:

  • Run using gunicorn using the uvicorn worker class.
  • Use one or two workers per-CPU core. (You might need to experiment with this.)
  • Disable access logging.

Eg.

gunicorn -w 4 -k uvicorn.workers.UvicornWorker --log-level warning example:app

Several of the ASGI servers also have pure Python implementations available, so you can also run under PyPy if your application code has parts that are CPU constrained.

Either programatically:

uvicorn.run(..., http='h11', loop='asyncio')

Or using Gunicorn:

gunicorn -k uvicorn.workers.UvicornH11Worker ...

⭐️

Starlette is BSD licensed code. Designed & built in Brighton, England.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].