Fast HTTP Server/Client microframework for Python asyncio
Project description
BlackSheep
HTTP Server/Client microframework for Python asyncio, using Cython,
uvloop, and
httptools.
pip install blacksheep
from datetime import datetime
from blacksheep.server import Application
from blacksheep.server.responses import text
app = Application()
@app.route('/')
async def home(request):
return text(f'Hello, World! {datetime.utcnow().isoformat()}'))
app.start()
Disclaimer
This project is currently targeting only Linux and CPython: support for Windows and other implementations
of Python language are currently out of the scope. However, a Pure-Python version of this framework is planned, with name
BlueSheep.
Objectives
- Clean architecture and source code, following SOLID principles
- Avoid CPU cycles to handle things that are not strictly necessary
- Intelligible and easy to learn API, similar to those of many Python web frameworks
- Keep the core package minimal and focused, as much as possible, on features defined in HTTP and HTML standards
- Targeting stateless applications to be deployed in the cloud
- High performance
Server Features
- Routing
- Middlewares
- Built-in support for multi processing
- Integration with built-in
loggingmodule to log access and errors synchronously - this is completely disabled by default - Chunked encoding through generators (yield syntax)
- Serving static files
Client Features
- Support for client side middlewares, enabling clean source code and separation of concerns (logging of different kinds, handling of cookies, etc.)
- HTTP connection pooling
- User friendly handling of SSL contexts (safe by default)
- Automatic handling of redirects (can be disabled, validates circular redirects and maximum number of redirects - redirects to URN are simply returned to code using the client)
- Automatic handling of cookies (can be disabled,
Set-CookieandCookieheaders)
Example:
import asyncio
from blacksheep.client import ClientSession
async def client_example(loop):
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)
loop = asyncio.get_event_loop()
loop.run_until_complete(client_example(loop))
Note
This project is in alpha stage. The reason behind this framework is described in this page of the Wiki: Story.
Documentation
Please refer to the project Wiki.
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-0.0.6.tar.gz
(669.7 kB
view details)
File details
Details for the file blacksheep-0.0.6.tar.gz.
File metadata
- Download URL: blacksheep-0.0.6.tar.gz
- Upload date:
- Size: 669.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30f86ce34c44eddcd0ec29bcdea144bf0f184abd068e9f5b28d01ccd93125777
|
|
| MD5 |
233e0d98852513d476017356c57b1ede
|
|
| BLAKE2b-256 |
7d17e5ea2934f6ce8cb73b115da5b097d71c2803963ef48d0caba0b58b083bb7
|