Skip to main content

Fast web framework for Python asyncio

Project description

Build pypi versions codecov license Join the chat at https://gitter.im/Neoteroi/BlackSheep documentation

BlackSheep

BlackSheep is an asynchronous web framework to build event based web applications with Python. It is inspired by Flask, ASP.NET Core, and the work by Yury Selivanov.

Black Sheep

pip install blacksheep

from datetime import datetime

from blacksheep import Application, get


app = Application()

@get("/")
async def home():
    return f"Hello, World! {datetime.utcnow().isoformat()}"

Getting started using the CLI ✨

BlackSheep offers a CLI to bootstrap new projects rapidly. To try it, first install the blacksheep-cli package:

pip install blacksheep-cli

Then use the blacksheep create command to bootstrap a project using one of the supported templates.

blacksheep create command

The CLI includes a help, and supports custom templates, using the same sources supported by Cookiecutter.

Getting started with the documentation

The documentation offers getting started tutorials:

These project templates can be used to start new applications faster:

Requirements

Python: any version listed in the project's classifiers. The current list is:

versions

BlackSheep belongs to the category of ASGI web frameworks, so it requires an ASGI HTTP server to run, such as uvicorn, or hypercorn. For example, to use it with uvicorn:

$ pip install uvicorn

To run an application like in the example above, use the methods provided by the ASGI HTTP Server:

# if the BlackSheep app is defined in a file `server.py`

$ uvicorn server:app

To run for production, refer to the documentation of the chosen ASGI server (i.e. for uvicorn).

Automatic bindings and dependency injection

BlackSheep supports automatic binding of values for request handlers, by type annotation or by conventions. See more here.

from dataclasses import dataclass

from blacksheep import Application, FromJSON, FromQuery, get, post


app = Application()


@dataclass
class CreateCatInput:
    name: str


@post("/api/cats")
async def example(data: FromJSON[CreateCatInput]):
    # in this example, data is bound automatically reading the JSON
    # payload and creating an instance of `CreateCatInput`
    ...


@get("/:culture_code/:area")
async def home(culture_code, area):
    # in this example, both parameters are obtained from routes with
    # matching names
    return f"Request for: {culture_code} {area}"


@get("/api/products")
def get_products(
    page: int = 1,
    size: int = 30,
    search: str = "",
):
    # this example illustrates support for implicit query parameters with
    # default values
    # since the source of page, size, and search is not specified and no
    # route parameter matches their name, they are obtained from query string
    ...


@get("/api/products2")
def get_products2(
    page: FromQuery[int] = FromQuery(1),
    size: FromQuery[int] = FromQuery(30),
    search: FromQuery[str] = FromQuery(""),
):
    # this example illustrates support for explicit query parameters with
    # default values
    # in this case, parameters are explicitly read from query string
    ...

It also supports dependency injection, a feature that provides a consistent and clean way to use dependencies in request handlers.

Generation of OpenAPI Documentation

Generation of OpenAPI Documentation.

Strategies to handle authentication and authorization

BlackSheep implements strategies to handle authentication and authorization. These features are documented here:

app.use_authentication()\
    .add(ExampleAuthenticationHandler())


app.use_authorization()\
    .add(AdminsPolicy())


@auth("admin")
@get("/")
async def only_for_admins():
    ...


@auth()
@get("/")
async def only_for_authenticated_users():
    ...

Since version 1.2.1, BlackSheep implements:

Meaning that it is easy to integrate with services such as:

Refer to the documentation for more details and examples.

Web framework features

Client features

BlackSheep includes an HTTP Client.

Example:

import asyncio

from blacksheep.client import ClientSession


async def client_example():
    async with ClientSession() as client:
        response = await client.get("https://docs.python.org/3/")

        assert response is not None
        text = await response.text()
        print(text)


asyncio.run(client_example())

Supported platforms and runtimes

  • Python: all versions included in the build matrix
  • Ubuntu
  • Windows 10
  • macOS

Documentation

Please refer to the documentation website.

Communication

BlackSheep community in Gitter.

Branches

The main branch contains the currently developed version, which is version 2 alpha. The v1 branch contains version 1 of the web framework, for bugs fixes and maintenance.

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

blacksheep-2.0.2.tar.gz (1.1 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

blacksheep-2.0.2-cp312-cp312-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.12Windows x86-64

blacksheep-2.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

blacksheep-2.0.2-cp312-cp312-macosx_10_9_universal2.whl (2.3 MB view details)

Uploaded CPython 3.12macOS 10.9+ universal2 (ARM64, x86-64)

blacksheep-2.0.2-cp311-cp311-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.11Windows x86-64

blacksheep-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

blacksheep-2.0.2-cp311-cp311-macosx_10_9_universal2.whl (2.3 MB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

blacksheep-2.0.2-cp310-cp310-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.10Windows x86-64

blacksheep-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

blacksheep-2.0.2-cp310-cp310-macosx_11_0_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

blacksheep-2.0.2-cp39-cp39-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.9Windows x86-64

blacksheep-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

blacksheep-2.0.2-cp39-cp39-macosx_11_0_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

blacksheep-2.0.2-cp38-cp38-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.8Windows x86-64

blacksheep-2.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

blacksheep-2.0.2-cp38-cp38-macosx_11_0_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.8macOS 11.0+ x86-64

File details

Details for the file blacksheep-2.0.2.tar.gz.

File metadata

  • Download URL: blacksheep-2.0.2.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for blacksheep-2.0.2.tar.gz
Algorithm Hash digest
SHA256 8c63ca62f62207f3650f258f3a21d44c80e122846dafee12f765880c1c536a4f
MD5 d4dd9046bc9abf00610f620e582c6a14
BLAKE2b-256 cb7bc5f87970d533565160720936e7ff94b7e3ef3581e1c3bd8c0d62de17e0ce

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: blacksheep-2.0.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for blacksheep-2.0.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5243f8fcc427bbdabcf14d1360a570f24b3f488f9ca4b657743f02504c929af5
MD5 8f955a7f4ac67d0cb7a0f3e782623ebf
BLAKE2b-256 0958134a170460d792e61eb8fb7b823d51cb3de5025321b441146ef336094ab0

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blacksheep-2.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2c1638ec0f905bf35ce159623c68252e53193484306afd0c99bb2b1a507feb45
MD5 85d682acab621f6d4c67331e6cd9f1da
BLAKE2b-256 aec9cbea6c78b06f5ad0f7b733001f5074e053edbe3307cca2872b54137509f4

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp312-cp312-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for blacksheep-2.0.2-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a9fd71fc6d314e584e99176adf2641595a7ed3c1709b46adc0936b56aae6a9a5
MD5 f3595ee5a8a0f6a37f7db167cc768c41
BLAKE2b-256 dc2b3c3e0b3e6b8bea4d739119d83d6ec8e57f91e06ec80c993a87db161cae3b

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: blacksheep-2.0.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for blacksheep-2.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1323f699ef5b9a7ab43cd1a5bd0a351a80cb9c54da77d806154af5542d5e1b12
MD5 4fe4f39da94ed1c329112523bd29b81e
BLAKE2b-256 3ec22e92cb69a27871d1e9be228903400b21b2759e9e258782edfbe8e7bb2d4e

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blacksheep-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e159a6fa7d6e754a89bddf6e61a1d67580b8e8fdd74eac8fe7c95e9850606d8b
MD5 8570bd00c4f74931e368e8206605da82
BLAKE2b-256 899381cf232f94d05e4785b007ffdb7afbcbea2da397687d9337624e39a2634f

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for blacksheep-2.0.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 8b5eb710aa655e0306bf7b13f7df098ce17694472f940edd45498c0c2f3dfa99
MD5 4f7d730cdf171736d7fa0c585a8750be
BLAKE2b-256 4a71999c5c7394455d8571dd66a241ee92152cfa696f3605159e58faf8604e99

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: blacksheep-2.0.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for blacksheep-2.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e629e81f6b3df2116e639705b678bd933e74bf263c19abf958b84c7ea179704a
MD5 43e5cb2fcf993ec4c919d2b4f014b560
BLAKE2b-256 22d8583aa8ddc907fc01b3fd4abf6b0b2e49064f715e6319aee57fbd6f445340

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blacksheep-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 495341cee70cc06e075a61188aa6cf9f231542d5d45ef24d3759b601440f6da4
MD5 1687df1b7211e36e3684477819e2b79f
BLAKE2b-256 12eb2b67376bf885da0650391d0d152f62bd10bd626a2561c99b52da4c545cc1

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for blacksheep-2.0.2-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 204c33666ec560f57732c21dc56abaa7a7ec9bd2d8ec6e23ff11f1f296b5aba3
MD5 fac7432db8973e3f9ad68d7d4c85d7eb
BLAKE2b-256 544408d5b3a9726bc4706e6450fa5c5b13d58db43b44f1cd05effb26b4437841

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: blacksheep-2.0.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for blacksheep-2.0.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fb76d1860a971f8f37159038e7fde1d801c6a7e96693bb1275af243ad2d0b395
MD5 3576db55d59a381fb8051e59735ccb71
BLAKE2b-256 844396a45cdc36ceac4f0d1549db4698c4849fe0a4c2fd5ccb5e290337b3e4d5

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blacksheep-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 49c90549be1ad31c6d5c9e727992f3ea9508eede33e0cf040d9c9be304a385d5
MD5 8d99ee66d4d308bf975d3802f8db8d62
BLAKE2b-256 e0fd624cca7033abf67978e9973f5ad6da28bba76241c0c7fcdda6ed4f288d04

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for blacksheep-2.0.2-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 62b73a14f73315f61e2d90e77f42d01ff120d200aa138764c345cdabef794ebb
MD5 10610ee12e40524128c5a02220d7804f
BLAKE2b-256 a6a7fe89835484252f94c43ac9f6d0303bed82a892123e65c40b040fbaec438c

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: blacksheep-2.0.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for blacksheep-2.0.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8dd4968f1f25abc2e0d673e81fd49825968766537f9913ff200aceeb2325649f
MD5 b1f6b7cda00d85156095d2dca448f001
BLAKE2b-256 fd39ea1a2ad747a95513c009ae1dc5a049e45efb62c8519893d003fc4e64162c

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blacksheep-2.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 245c6c90516b5bff923a44339c2961c51f333ccc718264fa45e9d6be8e06f3a9
MD5 c91b414a2df836130b0fb94fb6972356
BLAKE2b-256 12fb0ccd8f690d9a0cb91f6b712608c0db22368f6f2409d58b0169950b4e3a77

See more details on using hashes here.

File details

Details for the file blacksheep-2.0.2-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for blacksheep-2.0.2-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c5006e17a229f5108219853551e6bd74ef76d61d77b95d24e2a48f9320e38603
MD5 f14703da0d9cea2c4e7a679c70234240
BLAKE2b-256 bb9298844a22a166c699ca3713df8716836658efb8dc2ba2d3b36447fb0b233c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page