This repository demonstrates how to integrate Permit.io with FastAPI to implement robust, multi-tenant Role-Based Access Control (RBAC).
- FastAPI integration with Permit.io SDK
- User synchronization with Permit.io
- Multi-tenant RBAC enforcement via middleware
- Protected API endpoints with permission checks
- Python 3.8 or higher
- A Permit.io account and API key
- Basic understanding of FastAPI and RBAC concepts
- Clone this repository:
git clone https://github.com/Tabintel/permit-fastapi.git
cd permit-fastapi- Install dependencies:
pip install -r requirements.txt- Create a
.envfile with your Permit.io API key:
PERMIT_API_KEY=your_permit_api_key
PERMIT_PDP_URL=http://localhost:7766
Start the FastAPI server:
uvicorn main:app --reloadThe API will be available at http://localhost:8000
GET /- Welcome messageGET /admin- Admin dashboard (requires 'view' permission on 'admin_dashboard')GET /profile- User profile (requires 'view' permission on 'user_profile')POST /sync-user- Sync a user with Permit.io
main.py- FastAPI application and routespermit_client.py- Permit.io SDK initializationmiddleware/authorize.py- Authorization middlewareutils/sync_user.py- User synchronization utility
For more information about Permit.io and FastAPI: