{"library":"piccolo-api","title":"Piccolo API Utilities","description":"Piccolo API provides utilities for integrating the Piccolo ORM with ASGI applications. It includes essential ASGI middleware for common tasks like authentication (JWT, sessions, MFA) and rate limiting. The library is actively maintained, with regular releases (currently v1.9.0) addressing dependency updates, Python version support, and new features like Multi-Factor Authentication.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install piccolo-api","pip install \"piccolo-api[mfa]\""],"cli":{"name":"piccolo","version":"Can't import the APP_REGISTRY from piccolo_conf - some commands may be missing. If this is a new project don't worry. To see a full traceback use `piccolo --diagnose`"}},"imports":["from piccolo_api import JWTAuth","from piccolo_api import SessionsAuthBackend","from piccolo_api import RateLimitMiddleware"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom starlette.applications import Starlette\nfrom starlette.responses import JSONResponse\nfrom starlette.routing import Route\n\nfrom piccolo_api import JWTAuth\n\n# For demonstration, typically loaded from environment variables\nSECRET_KEY = os.environ.get('JWT_SECRET_KEY', 'your_super_secret_key_here')\n\nasync def homepage(request):\n    return JSONResponse({'hello': 'world'})\n\nasync def protected_route(request):\n    return JSONResponse({'data': 'This is protected data!'})\n\nroutes = [\n    Route('/', homepage),\n    Route('/protected', protected_route)\n]\n\nmiddleware = [\n    JWTAuth(\n        secret_key=SECRET_KEY,\n        # Exclude paths that don't require authentication\n        excluded_paths=['/', '/docs'], \n        # Allow an endpoint to create a token for testing\n        # In a real app, this would be a login endpoint\n        get_token_response=lambda user_id: JSONResponse({'token': f'fake-jwt-token-for-{user_id}'})\n    )\n]\n\napp = Starlette(routes=routes, middleware=middleware)\n\n# To run this:\n# uvicorn your_module_name:app --port 8000 --reload\n# Access with: http://127.0.0.1:8000/\n# Try http://127.0.0.1:8000/protected with a valid JWT in Authorization header\n# You can use the get_token_response for generating a dummy token in dev.","lang":"python","description":"This quickstart demonstrates how to set up a basic Starlette application with JWT authentication using `piccolo-api`. It includes a public and a protected route, and shows how to configure `JWTAuth` middleware with a secret key and excluded paths. Remember to manage your secret keys securely, ideally via environment variables.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}