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.3.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.3-cp312-cp312-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.12Windows x86-64

blacksheep-2.0.3-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.3-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.3-cp311-cp311-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.11Windows x86-64

blacksheep-2.0.3-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.3-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.3-cp310-cp310-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.10Windows x86-64

blacksheep-2.0.3-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.3-cp310-cp310-macosx_11_0_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

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

Uploaded CPython 3.9Windows x86-64

blacksheep-2.0.3-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.3-cp39-cp39-macosx_11_0_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

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

Uploaded CPython 3.8Windows x86-64

blacksheep-2.0.3-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.3-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.3.tar.gz.

File metadata

  • Download URL: blacksheep-2.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 998f9e4808f68df9b7ba163ef92886f3cb00318a4d416f2229b54080772f3d36
MD5 8c620de21e9f04d0c4365dcec4766ce9
BLAKE2b-256 a238a1384cc3905f603331c9d533cc11224d6a8fb50e66df8debfd0dc1035422

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blacksheep-2.0.3-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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9b4724c1a925132dae898af79f9a63cf2771075a9dc579f31deb5eab80e0f75c
MD5 9ebab0583d8ca33febc45c1fc2febabc
BLAKE2b-256 16d325fbd8a47f4979fc69a3356f98b6bb8a98ae3b1cec5339035bbafb6099ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blacksheep-2.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e53904b6d923b22dece7dfc11234d07946eb39f1dd36601a4885e4ec20a38284
MD5 8eb821df3a632ca310bb08994bca8c2a
BLAKE2b-256 3d549b3a167855791a1ef58ad66456f883677e1cbcda814ccf414fdeb0e88774

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blacksheep-2.0.3-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 8123308aa5a52bd0f932ac04d79a881edc7317869f94939fc734b6efc2c47601
MD5 c7ad65368179eabf4830f56a5cff82e3
BLAKE2b-256 34528aa9bec8b8ffdc6b7af6e496d5db213651b4f63fd3905f9f7cddc7c93e60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blacksheep-2.0.3-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.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3f54df38e88fdad5bb72b8be6c1cdd276e9b524cac6ba42a2a07fa01417027ee
MD5 e3b5a7fdd8e187a6207546775706b0be
BLAKE2b-256 6143375a7e29d4c6c34454697fb8f394f20e8e9cb5b14be32c7990475b87b423

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blacksheep-2.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cab16d1b770c25531a4e6ee17cbce2780b69f11e6b671554772c0c862ec5b437
MD5 a1492e35342691c937aa929e1f3a60d3
BLAKE2b-256 5b6a343d88a23ab73e7d6da7923e4231eba03743121546d262e20ff4bcae1b07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blacksheep-2.0.3-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 9c8efad3f88b3969dd681792ba2a18b832f1a6c8728feb0da0824d203f431b8f
MD5 271dedd7135ed7bd45b29a13d0b1f3f9
BLAKE2b-256 2a3964bf138e13f67f6c5be7071a89456534c6cafbcd161640e32c09c7ea00ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blacksheep-2.0.3-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.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e6352bae24cca980a011ad4302d1f3c6b80b432f4548e5538a09b2608b549558
MD5 79fddafb72bf35b8410fffb71f0d09f6
BLAKE2b-256 7121bad49028b44d64da51c1c8825f5d807b169daff4ca7228dbf97afd5e0fd0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blacksheep-2.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 72ac764a1177bc8fe741a9a2148b2f03547727d7135425507bdb3f7f2cb14550
MD5 7c59bbae6b60d25fe21cb73e9e315b36
BLAKE2b-256 d91b472970ab9c8a94d060ba71a2d70cb811dde915d0744f1bcf863c82eb3a5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blacksheep-2.0.3-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 23bf26ce6602cd3e1d08049cb5a160e5a813283bdb7648c6cfbf6552efd70971
MD5 36dd6fa990eac105d57ca9390b3b3f22
BLAKE2b-256 10d11130a09ad04e91859d6e641b0e25842bbb68adde9a0369bbe5063304952d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blacksheep-2.0.3-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.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7a34b8417ae8238c1fad196bc235e1bcb226f06d6b78be121224cd9b3787bcac
MD5 ccff411e573d699eb078572bae3a3461
BLAKE2b-256 fce21641fe21f9a94f32fc5e8d5773b8b6a2f1e56fcddcc00a38bf77c39244a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blacksheep-2.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b4bc5e911e7514a7e0ec0889a4c2e28b01efdf67408832747dac8dc0ff9b53e
MD5 4fe4cd56102687be50b83e99d77c7102
BLAKE2b-256 8ffa806ceceb5bf8781b5607ff0d154332aa4deeb7189c574168e775fdb9dc69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blacksheep-2.0.3-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 8c6e22e224085474ff437b6ed0da7ea78ca041a18d7e1f9f55c4362ec2428e9a
MD5 19ede7fb05eeda75a112e34f06745da8
BLAKE2b-256 ab127dd6d20f96d775a8fa657a8572fbe71b3d4afbdf6cd926e9e25236d82328

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blacksheep-2.0.3-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.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b33c1dadd1ff79670e72f6fcadc501aeb21ba613647a31c73cb36207850a15c1
MD5 86fdd0711c2d2a51210ef1f98a85edd9
BLAKE2b-256 ff41553560592ae9008beceda896c13294e75f94ad095bfdf82b8f0042dc94cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blacksheep-2.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dbff4afe5e76645de42f0b7b31f7a36b92d6dfc39a37c183a5d1ca4c6132c659
MD5 1b1d7d72083c86ad17fd0f36e332cc53
BLAKE2b-256 dc8c80aacf94f9b0bf21f5d1cb0646cb52b20c5212414d1c2d13d1f600f0d782

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blacksheep-2.0.3-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 3f97512fb50081805a3313ca25d7af2d5ba9f5f22ba197342cfb137a4b170f74
MD5 21919049353643108af41a9000a8c196
BLAKE2b-256 26eff7405e525bab7ee3f712f5926c4282e2d846ad95505e14f3391010e3d6df

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