DEV Community

Cover image for SlimeWeb --New Python WebFramework backed by rust
ATOM_MAX
ATOM_MAX

Posted on

SlimeWeb --New Python WebFramework backed by rust

Over the past few weeks, I’ve been experimenting with building a small web framework that combines Python’s simplicity with Rust’s performance.

The idea is pretty straightforward

  • Use rust for networking to handle request
  • Use python for business logic

Why this project?:
Frameworks like Flask and FastAPI are awesome, but I was curious about Python web frameworks' request-handling limits. Benchmarks on my machine showed pretty low numbers, so I thought, what if we offload the networking part to Rust and focus purely on business logic?. Introducing SlimeWeb. Its still early stage and experimenting but works.

Some of the things its currently supports:

  • Python handler functions
  • Rust powered HTTP server
  • Multiple worker pool model
  • Sync & Async handler
  • Multipart form support
  • File uploads
  • Streaming Response
  • Cookie signing
  • Custom headers
  • JSON / HTML / Raw Response
  • Templates rendering with context
  • Static serving
  • Hot reload of templates in dev mode
  • WebSocket

Sample Code:

from slimeweb import Slime

app = Slime(__file__)

@app.route(path="/", method="GET")
def home(req, resp):
    return resp.plain("Hello World from slime")

if __name__ == "__main__":
    app.serve(dev=True)
Enter fullscreen mode Exit fullscreen mode

The project is aimed at developers who wants to build APi's/backend services. who wanna use the power of rust networking.

In Microbenchmark for sync handlers ive tested on linux with 8cpu cores with same python runtime and 8worker using wrk. It beat both flask and fastapi.

Benchmark graph

Pypi: SlimeWeb Package (pip install SlimeWeb) & docs

Any suggestions, criticism, or feedback would really help.

Thank You ❤️

Top comments (0)