Python Version License: MIT PyPI version

The Modern Python Web Framework

Xyra is a lightweight and fast Python web framework built on socketify for high-performance applications. It offers flexible routing, WebSocket support, and automatic API documentation.

✨ Key Features

🚀

High Performance

Built on socketify.py for exceptional speed and low latency

Asynchronous

Full async/await support for non-blocking operations

🎯

Simple API

Intuitive design inspired by Flask and Express.js

🔧

Middleware Support

Easily add logging, authentication, CORS, and more

📚

Auto API Docs

Built-in Swagger/OpenAPI documentation generation

🔌

WebSocket Support

Real-time communication out of the box

📄

Templating

Jinja2 integration for HTML rendering

📁

Static Files

Efficient static file serving

🛡️

Type Safety

Full type hints support

📦 Installation

Install Xyra using pip:

Bash
pip install xyra

Or install from source for the latest features:

Bash
git clone https://github.com/xyra-python/xyra.git
cd xyra
pip install -e .

🚀 Quick Start

Get your first Xyra app running in seconds.

Python
from xyra import App, Request, Response

app = App()

@app.get("/")
def home(req: Request, res: Response):
    res.json({"message": "Hello, Xyra!"})

if __name__ == "__main__":
    app.listen(8000, logger=True)

Run the application:

Bash
python app.py

Visit http://localhost:8000 to see your app in action!

📖 Documentation

🎯 Example Applications

REST API

Python
from xyra import App, Request, Response

app = App()

# In-memory storage
users = []

@app.get("/api/users")
def get_users(req: Request, res: Response):
    res.json(users)

@app.post("/api/users")
async def create_user(req: Request, res: Response):
    user_data = await req.json()
    user_data["id"] = len(users) + 1
    users.append(user_data)
    res.status(201).json(user_data)

if __name__ == "__main__":
    app.listen(8000)

WebSocket Chat

Python
from xyra import App

app = App()
clients = set()

def on_open(ws):
    clients.add(ws)
    ws.send("Welcome to chat!")

def on_message(ws, message, opcode):
    for client in clients:
        if client != ws:
            client.send(f"User: {message}")

def on_close(ws, code, message):
    clients.discard(ws)

app.websocket("/chat", {
    "open": on_open,
    "message": on_message,
    "close": on_close
})

if __name__ == "__main__":
    app.listen(8000)

HTML with Templates

Python
from xyra import App, Request, Response

app = App(templates_directory="templates")

@app.get("/")
def home(req: Request, res: Response):
    res.render("home.html", title="My App", users=["Alice", "Bob"])

if __name__ == "__main__":
    app.listen(8000)

🤝 Contributing

We welcome contributions! Here's how you can help:

1. Fork the repository
2. Create a feature branch: git checkout -b feature/amazing-feature
3. Commit your changes: git commit -m 'Add amazing feature'
4. Push to the branch: git push origin feature/amazing-feature
5. Open a Pull Request

Development Setup

Bash
git clone https://github.com/xyra-python/xyra.git
cd xyra
pip install -e .[dev]
pytest

We use Black for code formatting, isort for import sorting, flake8 for linting, and mypy for type checking.

📄 License & Acknowledgments

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments:

  • Built on top of socketify.py
  • Inspired by Flask, Express.js, and FastAPI
  • Thanks to all our contributors!

📞 Support