DEV Community

Ciro Spaciari
Ciro Spaciari

Posted on

Adding better DX to the fastest Python WebFramework

After more than a year of active development, I finally publish my package to PyPI!

pip install socketify
Enter fullscreen mode Exit fullscreen mode

After some people asks to also create a WSGI and ASGI server to improve projects using other frameworks, I worked hard to get it right.

But in the end, we outperform uvicorn and meinheld with Flask, Django, Emmett, FastAPI, and Falcon in TechEmPower plaintext with our WSGI and ASGI servers!

And we got the Top 1 with socketify itself!

https://www.techempower.com/benchmarks/#section=test&runid=7ce481b2-49ec-4a4d-952d-bb1334d4a4ad&test=plaintext&l=hra0hr-35r

Also added a CLI tool with very familiar options for uvicorn and gunicorn users

CLI: https://docs.socketify.dev/cli.html

Also added lifespan (start and shutdown) events to socketify itself, and added an improved DX for routing and support to Extensions/Plugins.

# main.py
from socketify import App

def run(app: App):
    @app.on_start
    async def on_start():
        # we can start connection pools here
        pass

    @app.on_shutdown
    async def on_shutdown():
        # and here we can clean connection pools
        pass

    router = app.router()
    api = app.router(prefix="/api")
    private = app.router("/api", auth_middleware)

    @router.get("/")
    def home(res, req):
        res.send("Hello, World!")

    # will serve in /api/hello
    @api.get("/hello") 
    def hello(res, req):
       res.send("Hello API!")

    # will serve in /api/users and use auth_middleware
    @private.get("/users")
    def get_users(res, req, auth):
       res.send("Hello private API!")
Enter fullscreen mode Exit fullscreen mode
 python3 -m socketify main:run --port 8080 --workers 2
Enter fullscreen mode Exit fullscreen mode

About Extensions: https://docs.socketify.dev/extensions.html

My focus until v0.1.0 now will be to add features to help developers and add more optimizations.

Are there any features that you want to see in the future? I will love to get community feedback!

Project: https://github.com/cirospaciari/socketify.py

Issues and Planned Features: https://github.com/cirospaciari/socketify.py/issues

Releases: https://github.com/cirospaciari/socketify.py/releases

Top comments (0)