Fastapi | Tutorial Pdf [better]
FastAPI is built on top of Starlette for the web parts and Pydantic for the data parts. It is designed to be easy to use for developers while providing production-grade performance. Key features include:
from sqlalchemy import Column, Integer, String from database import Base class DBUser(Base): __tablename__ = "users" id = Column(Integer, primary_key=True, index=True) username = Column(String, unique=True, index=True) email = Column(String, unique=True, index=True) Use code with caution. 3. Dependency Injection in Routes ( main.py )
from fastapi import Header, HTTPException async def verify_token(x_token: str = Header(...)): if x_token != "super-secret-token": raise HTTPException(status_code=400, detail="X-Token header invalid") return x_token @app.get("/protected-data/", dependencies=[Depends(verify_token)]) def get_protected_data(): return "data": "This is highly secured information." Use code with caution. 8. Authentication and Security (JWT)
| Concept | Code Snippet | |---------|---------------| | Basic app | app = FastAPI() | | GET | @app.get("/path") | | POST | @app.post("/path") | | Path param | def fn(item_id: int) | | Query param | def fn(q: str = None) | | Body | def fn(item: Item) | | Depends | def fn(db = Depends(get_db)) | | Exception | raise HTTPException(404, "msg") | | Response model | @app.get("/", response_model=Item) | | Docs URL | /docs or /redoc | fastapi tutorial pdf
from fastapi import FastAPI, Query, Path app = FastAPI() @app.get("/products/product_id") def get_product( product_id: int = Path(..., title="The ID of the product", ge=1), q: str = Query(None, min_length=3, max_length=50) ): return "product_id": product_id, "search_query": q Use code with caution.
class Item(BaseModel): name: str price: float is_offer: bool = False # default value
Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic) 1. FastAPI is built on top of Starlette for
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
FastAPI does not require a specific database, but it works seamlessly with SQLAlchemy, Tortoise ORM, and databases like PostgreSQL, MySQL, and SQLite. Using an asynchronous database driver is recommended to leverage FastAPI's performance. Summary and PDF Export
FastAPI reads the incoming JSON, validates the data types against the Product model, and passes it to the function as a clean Python object. Connecting a Database (SQLAlchemy & Tortoise) Authentication and Security (JWT) | Concept | Code
Middlewares process requests before they reach path routing endpoints, and modify responses before they leave.
from pydantic import BaseModel, EmailStr class UserBase(BaseModel): email: EmailStr class UserCreate(UserBase): password: str class UserResponse(UserBase): id: int is_active: bool class Config: orm_mode = True Use code with caution. crud.py Handles database queries and operations.
Hi,
Thanks for the post. Might you have a script or the procedure on Oracle 11gR2 installation on Oracle Linux 6.4?
Thanks.
I’ve just finished off a post here Lucas: http://snapdba.com/2013/05/oracle-database-11gr2-11-2-0-3-installation-on-oracle-linux-6-4/
How you allocated the partitions – except that everything is clear.
Yeah i m done with the partitions as well, installed it on Virtual Box 4.3, Linux 6.4, Weblogic 12.1.1 – successfully installed.
Thanks a lot. Its very simple step by step guide for Installation of Linux and Oracle 12c.
Garth,
This is a brilliant tutorial mate. Concise, clear and just great. I wish everything in IT was like Garth !!!
You have saved me many hours of frustration and saved me a good bit of hair loss.
Cheers.
Hello,
About Oracle account installation, a preinstall package is available for Oracle Linux 6 (and soon for Oracle Linux 7)
Syntax of the package is oracle-rdbms-server–preinstall
oracle-rdbms-server-11gR2-preinstall for 11gR2
oracle-rdbms-server-12cR1-preinstall for 12cR1
(See http://www.oracle.com/technetwork/articles/servers-storage-admin/ginnydbinstallonlinux-488779.html for further details)
Thanks for the post!