Getting Started with Sufast
Learn how to install and create your first Sufast application in minutes.
Installation
Install Sufast using pip. The package includes a pre-compiled Rust binary for optimal performance.
pip install sufastYour First Sufast App
Create a simple "Hello World" application to verify your installation.
from sufast import App
app = App()
@app.get("/")
def hello():
return {"message": "Hello from Sufast π"}
if __name__ == "__main__":
app.run()Run your application:
python hello.pyYour app will be available at http://localhost:8080
Building an API Server
Let's create a more comprehensive example with multiple endpoints and data handling.
from sufast import App
app = App()
# Sample database
users = {
"shohan": {"name": "Shohan", "email": "shohan@example.com"},
"bob": {"name": "Bob", "email": "bob@example.com"},
"alice": {"name": "Alice", "email": "alice@example.com"},
}
@app.get("/")
def home():
return {"message": "Welcome to Sufast API π"}
@app.get("/users")
def get_users():
return {"users": list(users.values())}
@app.get("/users/{user_id}")
def get_user(user_id: str):
if user_id in users:
return {"user": users[user_id]}
return {"error": "User not found"}, 404
@app.post("/users")
def create_user():
# This is a mocked POST example
return {
"message": "User created successfully",
"user": users["bob"]
}
@app.get("/health")
def health_check():
return {"status": "healthy", "framework": "Sufast"}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)Testing Your API
Test your API endpoints using curl or any HTTP client.
curl http://localhost:8080/curl http://localhost:8080/userscurl http://localhost:8080/users/shohancurl -X POST http://localhost:8080/usersYou're now ready to explore more advanced features like middleware, authentication, database integration, and performance optimization.