Skip to main content

Python web framework

Project description

sherry

Python web framework

pip install sherry

Simple application

from sherry import Sherry, get, Request

hi_str = "hi {}"
app = Sherry()


@get("/", app)
def hello_world(request: Request):
    return hi_str.format(request.query.get("name") or "world")


app.run(9527)

Create application engine

from sherry import Sherry, Engine

app1 = Sherry()
# or
app2 = Engine()
# with regex
app3 = Engine(re=True)

Add handlers

Create handler

If a return value exists for the function, it will be converted to a response (if not)

def my_handler(*args, **kwargs) -> Response | Any:
    pass

If there is no return value, the response will be the response field of the first parameter

The second parameter is the response field of the first parameter

from sherry import Request, Response


def my_handler(ctx: Request) -> None:
    pass


def my_handler(req: Request, res: Response) -> None:
    """
    req.response == res # True
    """
    pass

Add route, method, handlers

app = Engine()
app.add_route("GET" """http method""", "/" """pattern""", handlers)
app.add_route("GET", "/:some" """match one dynamic""", handlers)
app.add_route("GET", "/xx/*any" """match multiple dynamic""", handlers)

with regex

app = Engine(re=True)
app.add_route("GET", "^/\d$" """match one number""", handlers)

Wrapping

app.get("/", handlers)
app.post("/", handlers)
...

Decorators

from sherry.decorators import handler, get  # ...


@handler("/" """pattern""", ["GET" """"http methods"""], app)
def func():
    pass


@get("/"  """pattern""", app)
def func():
    pass

example

from sherry import Engine, handler

app = Engine()


# function decorators
@handler("/", ["GET"], app)
def index_handler():
    pass


# as
app.add_route("GET", "/", index_handler)


# class decorators
@handler("/", ["GET"], app)
class Pages:
    def middle_handler():
        pass

    def index_handler():
        pass


# as
app.add_route("GET", Pages.middle_handler, Pages.index_handler)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sherry-0.0.6.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

sherry-0.0.6-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file sherry-0.0.6.tar.gz.

File metadata

  • Download URL: sherry-0.0.6.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for sherry-0.0.6.tar.gz
Algorithm Hash digest
SHA256 62b5a722ecbb544851779388a20b2d0462fb8c2655b154f2987b5dac03749eae
MD5 be93a48240ff74cd89d68dd2cf5130c2
BLAKE2b-256 f9af2fdf10774cc3d6e4e97b751c95382629d278cefc77664b839a3ee4f955ef

See more details on using hashes here.

File details

Details for the file sherry-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: sherry-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for sherry-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 27f4f8a9ad96053cf2422b2eab1ca04e0ed3ebd8c64e517c5db3fc21c890483a
MD5 24ca4ca566164722e422e97910b52f0e
BLAKE2b-256 040e034d87d684e81abdc2e1a5b12193a3ee953c3a9a642f1e1d553ec610dff0

See more details on using hashes here.

Supported by

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