BlackSheep
raw JSON → 2.6.2 verified Fri May 01 auth: no python
A fast ASGI web framework for building asynchronous web applications in Python, featuring automatic OpenAPI documentation generation, dependency injection, and built-in HTTP client. Current version 2.6.2, supporting Python 3.10+. Active development with monthly releases on GitHub.
pip install blacksheep Common errors
error ImportError: cannot import name 'Application' from 'blacksheep' ↓
cause Installed version is older than v2.0 or import path changed.
fix
Upgrade to latest: pip install --upgrade blacksheep. If still failing, use from blacksheep.server import Application for older versions.
error TypeError: 'function' object is not subscriptable ↓
cause Using synchronous handler or missing proper route decorator parentheses.
fix
Ensure handler is async and use @get('/') with parentheses, not @get('/') without calling.
error RuntimeError: You must use `await` on the request body methods ↓
cause Calling Request methods like .json() or .form() without await inside async handler.
fix
Use await request.json() or await request.form().
Warnings
breaking In v2.0+, the Application class no longer takes an 'app' parameter (previously used for wsgi). Use Application() directly. ↓
fix Remove any arguments from Application instantiation.
breaking The 'server' module was reorganized in v2.0. Most classes moved out of blacksheep.server to top-level. Importing from blacksheep.server for Request/Response/Application may fail. ↓
fix Update imports to top-level: from blacksheep import Request, Response, Application.
gotcha Route handlers must be async functions. Using synchronous functions will cause a runtime error or unexpected behavior. ↓
fix Define all handlers with async def.
gotcha When using the built-in HTTP client, ensure the event loop is running. Instantiating blacksheep.client.Client outside an async context may cause deadlocks. ↓
fix Create the client inside an async function or use await client.open_async().
deprecated The 'auth_mode' parameter in JWTBearerAuthentication is deprecated since v2.4.3. Use 'scheme' instead. ↓
fix Replace auth_mode=... with scheme=... in JWTBearerAuthentication constructor.
Imports
- Application wrong
from blacksheep.server import Applicationcorrectfrom blacksheep import Application - Request wrong
from blacksheep.server import Requestcorrectfrom blacksheep import Request - Response
from blacksheep import Response - get wrong
from blacksheep import getcorrectfrom blacksheep.server.routing import get - Router wrong
from blacksheep.routing import Routercorrectfrom blacksheep.server.routing import Router - Inject wrong
from blacksheep import Injectcorrectfrom blacksheep.server.di import Inject
Quickstart
from blacksheep import Application, Request, Response
from blacksheep.server.routing import get
app = Application()
@get('/')
async def home(request: Request) -> str:
return 'Hello, World!'
# Run using: uvicorn main:app