FastAPI Snippets - VS Code Extension
📌 Overview
FastAPI Snippets is a Visual Studio Code extension that provides a collection of useful FastAPI code snippets to speed up your development process.
🚀 Features
- Quickly generate FastAPI boilerplate code.
- Includes snippets for GET, POST, PUT, DELETE endpoints.
- Supports async functions and JWT authentication.
- Includes database integration (SQLAlchemy, MySQL, PostgreSQL).
- Saves time and improves productivity.
🛠 Installation
- Open VS Code.
- Go to the Extensions marketplace.
- Search for
fastapi-snippets
.
- Click Install.
Alternatively, install manually using the .vsix
file:
code --install-extension fastapi-snippets.vsix
🔥 Usage
- Open a Python file in VS Code.
- Type the snippet prefix (e.g.,
fastapi-app
) and press Tab
.
- The snippet will auto-expand into a complete FastAPI code block.
Here’s the formatted table for your README.md
file:
📜 Available Snippets
Prefix |
Description |
fastapi-app |
Creates a basic FastAPI app. |
fastapi-get |
Creates a FastAPI endpoint with path parameters. |
fastapi-post |
Creates a FastAPI POST request handler with Pydantic validation. |
fastapi-db |
Sets up a SQLAlchemy database connection. |
fastapi-crud |
Implements CRUD operations with SQLAlchemy. |
fastapi-async-crud |
Implements async CRUD operations with SQLAlchemy. |
fastapi-auth-jwt |
Implements JWT authentication in FastAPI. |
fastapi-jwt-mysql |
Implements JWT authentication with MySQL. |
fastapi-bg-task |
Creates a FastAPI background task. |
fastapi-middleware |
Adds custom middleware to FastAPI. |
fastapi-dep |
Demonstrates dependency injection in FastAPI. |
fastapi-upload |
Creates a file upload endpoint. |
fastapi-websocket |
Implements a WebSocket endpoint. |
fastapi-async-ws |
Implements an async WebSocket endpoint. |
fastapi-async-upload |
Implements an async file upload endpoint. |
fastapi-async-bg |
Runs an async background task. |
fastapi-async-middleware |
Adds async middleware to FastAPI. |
fastapi-router |
Creates a simple FastAPI router. |
fastapi-router-params |
Creates a router with path and query parameters. |
fastapi-router-dep |
Creates a router with dependency injection. |
fastapi-router-nested |
Creates a router with nested routes. |
fastapi-router-version |
Implements versioned routing. |
fastapi-router-response |
Creates a router with response models. |
fastapi-router-middleware |
Adds middleware to a router. |
fastapi-router-auth |
Implements authentication in a router. |
fastapi-pagination |
Implements basic pagination. |
fastapi-rate-limit |
Implements rate-limiting using middleware. |
fastapi-exception |
Implements custom exception handling. |
fastapi-error-response |
Creates a custom error response. |
fastapi-cors |
Configures CORS (Cross-Origin Resource Sharing) in FastAPI.. |
You can copy and paste this table into your README.md
file. Let me know if you need further adjustments! 🚀
✨ Example Usage
Type fastapi-app
and press Tab
to generate:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def home():
return {"message": "Welcome to FastAPI!"}
📝 Contributing
Want to add more snippets? Feel free to contribute!
- Fork the repository.
- Add your snippets in
snippets/snippets.code-snippets
.
- Create a pull request.
🛠 Development & Publishing
To package and publish the extension:
vsce package
vsce publish
📌 License
This extension is licensed under the MIT License.
Enjoy coding with FastAPI! 🚀