Skip to content

Python Bindings

Compare
Choose a tag to compare
@Ethosa Ethosa released this 16 Aug 08:52
· 861 commits to master since this release
89cb8d9

Meet - Python Bindings! 👋

Since v2.2.4 you can use HappyX with Python 🐍

Install

pip install happyx

Usage

from happyx import new_server, HttpRequest, RequestModelBase, JsonResponse


class User(RequestModelBase):
    name: str
    age: int


app = new_server("127.0.0.1", 5000)
user = new_server()

app.mount("/user", user)

@app.get('/')
def home(request: HttpRequest):
    print(request)
    return "Hello, world!"

@user.get('/')
def user_home(a: int, b: float, c: bool = true):
    """
    Try to send GET request to localhost:5000/user/
    And try to send queries:
    ?a=5&b=10.4&c=off
    """
    return f"Hello, world! a={a}, b={b}, c={c}"

@user.post('/[u]')
def create_user(u: User):
    print(u)
    print(u.name)
    print(u.age)
    return u.to_dict()

app.start()

Changelog

  • Python Bindings 🐍 (#91)
  • Python in HappyX CLI (#105)

Full Changelog: v2.1.0...v2.2.4