id
stringlengths
16
145
text
stringlengths
1
179k
title
stringclasses
1 value
fastapi_security_advanced_user_guide/configuration_49_0.txt
Parameter name | Docker variable | Description ---|---|--- ` modelPropertyMacro ` | _Unavailable_ | ` Function ` . Function to set default values to each property in model. Accepts one argument modelPropertyMacro(property), property is immutable ` parameterMacro ` | _Unavailable_ | ` Function ` . Function to se...
fastapi_security_advanced_user_guide/fastapipythonwebapis_252_0.txt
With that Python type declaration, FastAPI will:
fastapi_security_advanced_user_guide/fastapi_security_6_9.txt
ill include all the routes from that router as part of it. Technical Details It will actually internally create a _path operation_ for each _path operation_ that was declared in the ` APIRouter ` . So, behind the scenes, it will actually work as if everything was the same single app. Check You don't have to worry ...
fastapi_security_advanced_user_guide/anintroductiontopyth_49_0.txt
Contact Accounts: [ Twitter ](https://twitter.com/AysellAydinn) , [ LinkedIn ](https://www.linkedin.com/in/aysel-aydin/)
fastapi_security_advanced_user_guide/fastapipythonwebapis_172_0.txt
from fastapi import FastAPI
fastapi_security_advanced_user_guide/fastapipythonwebapis_113_0.txt
With [ HTTP ](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) , you can communicate with each path using one (or more) of these operations. Knowing what those two terms mean, you’re ready to continue with step three.
fastapi_security_advanced_user_guide/fastapipythonwebapis_284_0.txt
### Request Body and Path Parameters
fastapi_security_advanced_user_guide/fastapipythonwebapis_173_0.txt
app = FastAPI()
fastapi_security_advanced_user_guide/fastapipythonwebapis_244_0.txt
# main.py
fastapi_security_advanced_user_guide/fastapipythonwebapis_196_0.txt
Again, with that same Python type declaration, FastAPI gives you automatic, interactive documentation integrating Swagger UI. Notice that the path parameter is declared to be an integer.
fastapi_security_advanced_user_guide/fastapipythonwebapis_106_0.txt
$ uvicorn main:app --reload
fastapi_security_advanced_user_guide/fastapipythonwebapis_362_0.txt
Start the Class »
fastapi_security_advanced_user_guide/fastapipythonwebapis_81_0.txt
### Check the Alternative Interactive API Documentation
fastapi_security_advanced_user_guide/fastapipythonwebapis_77_0.txt
Now open ` http://127.0.0.1:8000/docs ` in your browser.
fastapi_security_advanced_user_guide/fastapipythonwebapis_30_0.txt
Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: [ **Python REST APIs With FastAPI** ](/courses/python-rest- apis-with-fastapi/)
fastapi_security_advanced_user_guide/fastapipythonwebapis_120_0.txt
Copied!
fastapi_security_advanced_user_guide/fastapipythonwebapis_345_0.txt
**Rate this article:**
fastapi_security_advanced_user_guide/configuration_58_0.txt
##### String variables
fastapi_security_advanced_user_guide/fastapipythonwebapis_156_0.txt
Python
fastapi_security_advanced_user_guide/fastapi_security_7_0.txt
Skip to content [ Follow **@fastapi** on **Twitter** to stay updated ](https://twitter.com/fastapi) [ Subscribe to the **FastAPI and friends** newsletter 🎉 ](https://fastapi.tiangolo.com/newsletter/) [ You can now sponsor **FastAPI** 🍰 ](https://github.com/sponsors/tiangolo) [ sponsor ![](/img/sponsors/cryptapi-...
fastapi_security_advanced_user_guide/anintroductiontopyth_8_0.txt
![](https://miro.medium.com/v2/resize:fill:64:64/1*dmbNkD5D-u45r44go_cf0g.png)
fastapi_security_advanced_user_guide/anintroductiontopyth_54_0.txt
[ Api Development ](https://medium.com/tag/api-development?source=post_page -----fb68d8861fad---------------api_development-----------------)
fastapi_security_advanced_user_guide/fastapi_security_1_0.txt
Skip to content [ Follow **@fastapi** on **Twitter** to stay updated ](https://twitter.com/fastapi) [ Subscribe to the **FastAPI and friends** newsletter 🎉 ](https://fastapi.tiangolo.com/newsletter/) [ You can now sponsor **FastAPI** 🍰 ](https://github.com/sponsors/tiangolo) [ sponsor ![](/img/sponsors/cryptapi-...
fastapi_security_advanced_user_guide/fastapi_security_11_14.txt
detail="Inactive user") return current_user @app.post("/token") async def login(form_data: Annotated[OAuth2PasswordRequestForm, Depends()]): user_dict = fake_users_db.get(form_data.username) if not user_dict: raise HTTPException(status_code=400, detail="Incorrect u...
fastapi_security_advanced_user_guide/fastapi_security_3_3.txt
../../help-fastapi/) * [ Development - Contributing ](../../contributing/) * [ Release Notes ](../../release-notes/) Table of contents * Use ` StaticFiles ` * What is "Mounting" * Details * More info 1. [ FastAPI ](../..) 2. [ Learn ](../../learn/) 3. [ Tutorial - User Guide ](../) # ...
fastapi_security_advanced_user_guide/anintroductiontopyth_86_0.txt
](https://medium.com/business?source=post_page----- fb68d8861fad--------------------------------)
fastapi_security_advanced_user_guide/fastapipythonwebapis_192_0.txt
[ Remove ads ](/account/join/)
fastapi_security_advanced_user_guide/fastapi_security_10_1.txt
[ Declare Request Example Data ](../schema-extra-example/) * [ Extra Data Types ](../extra-data-types/) * [ Cookie Parameters ](../cookie-params/) * [ Header Parameters ](../header-params/) * [ Response Model - Return Type ](../response-model/) * [ Extra Models ](../extra-models/) ...
fastapi_security_advanced_user_guide/fastapipythonwebapis_18_0.txt
Mark as Completed
fastapi_security_advanced_user_guide/fastapipythonwebapis_76_0.txt
### Check the Interactive API Documentation
fastapi_security_advanced_user_guide/fastapipythonwebapis_254_0.txt
By using standard type hints with pydantic, FastAPI helps you build APIs that have all these best practices by default, with little effort.
fastapi_security_advanced_user_guide/thebenefits_13_0.txt
COPY from fastapi import FastAPI from fastapi.openapi.docs import get_swagger_ui_html
fastapi_security_advanced_user_guide/configuration_53_0.txt
**💡 Take note! These are methods, not parameters** .
fastapi_security_advanced_user_guide/fastapi_security_11_3.txt
* [ Encoders - ` jsonable_encoder ` ](../../../reference/encoders/) * [ Static Files - ` StaticFiles ` ](../../../reference/staticfiles/) * [ Templating - ` Jinja2Templates ` ](../../../reference/templating/) * [ Test Client - ` TestClient ` ](../../../reference/testclient/) * [ FastAPI People ](../...
fastapi_security_advanced_user_guide/anintroductiontopyth_75_0.txt
Careers
fastapi_security_advanced_user_guide/fastapipythonwebapis_50_0.txt
## First Steps
fastapi_security_advanced_user_guide/configuration_90_0.txt
Resources
fastapi_security_advanced_user_guide/thebenefits_2_0.txt
The benefits of using Swagger with FastAPI for your Python APIs The benefits of using Swagger with FastAPI for your Python APIs Improve the quality of your Python APIs with Swagger
fastapi_security_advanced_user_guide/thebenefits_14_0.txt
app = FastAPI()
fastapi_security_advanced_user_guide/configuration_61_0.txt
FILTER="myFilterValue" LAYOUT="BaseLayout"
fastapi_security_advanced_user_guide/configuration_22_0.txt
[ ![](/swagger/assets/images/SW_Menu3_1_CLR.svg) OpenAPI Specification ](/resources/open-api/ "OpenAPI Specification") [ ![](/swagger/assets/images/SW_Menu3_2_CLR.svg) Docs ](/docs/ "Docs") [ ![](/swagger/assets/images/SW_Menu3_3_CLR.svg) Blog ](/blog/ "Blog") [ ![](/swagger/assets/images/SW_Menu3_4_CLR.svg) Support ...
fastapi_security_advanced_user_guide/anintroductiontopyth_48_0.txt
](https://fastapi.tiangolo.com/?source=post_page----- fb68d8861fad--------------------------------)
fastapi_security_advanced_user_guide/fastapi_security_12_5.txt
ydantic import BaseModel app = FastAPI() oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") class User(BaseModel): username: str email: str | None = None full_name: str | None = None disabled: bool | None = None def fake_decode_token(toke...
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_3_1.txt
* [ Body - Fields ](../../tutorial/body-fields/) * [ Body - Nested Models ](../../tutorial/body-nested-models/) * [ Declare Request Example Data ](../../tutorial/schema-extra-example/) * [ Extra Data Types ](../../tutorial/extra-data-types/) * [ Cookie Parameters ](../../tutorial/cookie-pa...
fastapi_security_advanced_user_guide/fastapipythonwebapis_221_0.txt
### Use pydantic to Declare JSON Data Models (Data Shapes)
fastapi_security_advanced_user_guide/fastapipythonwebapis_116_0.txt
# main.py
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_8_5.txt
}, ) async def read_item(item_id: str, img: Union[bool, None] = None): if img: return FileResponse("image.png", media_type="image/png") else: return {"id": "foo", "value": "there goes my hero"} Note Notice that you have to return the image using a ` FileResp...
fastapi_security_advanced_user_guide/fastapipythonwebapis_6_0.txt
[ ](/search "Search") /
fastapi_security_advanced_user_guide/fastapipythonwebapis_232_0.txt
When a model attribute has a default value, it is not required. Otherwise, it is required. To make an attribute optional, you can use [ ` None ` ](https://realpython.com/null-in-python/) .
fastapi_security_advanced_user_guide/configuration_19_0.txt
[ Explore all tools __ ](/tools)
fastapi_security_advanced_user_guide/fastapipythonwebapis_348_0.txt
What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.
fastapi_security_advanced_user_guide/fastapipythonwebapis_359_0.txt
Almost there! Complete this form and click the button below to gain instant access:
fastapi_security_advanced_user_guide/fastapipythonwebapis_311_0.txt
🐍 Python Tricks 💌
fastapi_security_advanced_user_guide/fastapipythonwebapis_91_0.txt
from fastapi import FastAPI
fastapi_security_advanced_user_guide/fastapipythonwebapis_249_0.txt
@app.post("/items/") async def create_item(item: Item): return item
fastapi_security_advanced_user_guide/fastapipythonwebapis_58_0.txt
@app.get("/") async def root(): return {"message": "Hello World"}
fastapi_security_advanced_user_guide/fastapipythonwebapis_353_0.txt
Related Tutorial Categories: [ basics ](/tutorials/basics/) [ api ](/tutorials/api/) [ web-dev ](/tutorials/web-dev/)
fastapi_security_advanced_user_guide/fastapipythonwebapis_51_0.txt
To get started, in this section, you will create a minimal FastAPI app, run it with a server using Uvicorn, and then learn all the interacting parts. This will give you a very quick overview of how everything works.
fastapi_security_advanced_user_guide/fastapipythonwebapis_175_0.txt
Copied!
fastapi_security_advanced_user_guide/fastapi_security_1_5.txt
rite_log, message) return {"message": "Message sent"} Tip Prefer to use the ` Annotated ` version if possible. from typing import Union from fastapi import BackgroundTasks, Depends, FastAPI app = FastAPI() def write_log(message: str): with open("log....
fastapi_security_advanced_user_guide/anintroductiontopyth_16_0.txt
\--
fastapi_security_advanced_user_guide/fastapipythonwebapis_147_0.txt
from fastapi import FastAPI
fastapi_security_advanced_user_guide/fastapipythonwebapis_339_0.txt
[ Level Up Your Python Skills » ](/account/join/?utm_source=rp_article_footer&utm_content=fastapi-python-web- apis)
fastapi_security_advanced_user_guide/fastapipythonwebapis_269_0.txt
In this case, you cannot sum a ` str ` with a ` float ` , and as the editor knows those types, it can warn you that you have an error in your code. This is not by chance: The whole framework was built around that design. It was thoroughly tested at the design phase, before any implementation, to ensure it would work wi...
fastapi_security_advanced_user_guide/fastapi_security_7_6.txt
o", } def test_read_item_bad_token(): response = client.get("/items/foo", headers={"X-Token": "hailhydra"}) assert response.status_code == 400 assert response.json() == {"detail": "Invalid X-Token header"} def test_read_nonexistent_item(): response = c...
fastapi_security_advanced_user_guide/fastapipythonwebapis_88_0.txt
**Step 1** is to import ` FastAPI ` :
fastapi_security_advanced_user_guide/configuration_28_0.txt
* The ` swagger-config.yaml ` in the project root directory, if it exists, is baked into the application * configuration object passed as an argument to Swagger UI ( ` SwaggerUI({ ... }) ` ) * configuration document fetched from a specified ` configUrl ` * configuration items passed as key/value pairs in the URL query ...
fastapi_security_advanced_user_guide/fastapipythonwebapis_141_0.txt
@app.get("/") def root(): return {"message": "Hello World"}
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_1_2.txt
ifespan Events ](../events/) * [ Testing WebSockets ](../testing-websockets/) * [ Testing Events: startup - shutdown ](../testing-events/) * [ Testing Dependencies with Overrides ](../testing-dependencies/) * [ Testing a Database ](../testing-database/) * [ Async Tests ](../async-tes...
fastapi_security_advanced_user_guide/anintroductiontopyth_1_0.txt
Sign up
fastapi_security_advanced_user_guide/fastapipythonwebapis_302_0.txt
FastAPI can cover most of the use cases required for back-end frameworks, even the ones that are not strictly APIs. You can dive deeper into the documentation to solve your specific use case.
fastapi_security_advanced_user_guide/fastapipythonwebapis_19_0.txt
[ ](/feedback/survey/article/fastapi-python-web-apis/liked/?from=article- sidebar "Liked it") [ ](/feedback/survey/article/fastapi-python-web- apis/disliked/?from=article-sidebar "Disliked it")
fastapi_security_advanced_user_guide/fastapipythonwebapis_155_0.txt
You can declare path **parameters** or **variables** with the same syntax used by Python [ formatted strings ](https://realpython.com/python-formatted- output/) :
fastapi_security_advanced_user_guide/fastapipythonwebapis_70_0.txt
Open your browser to ` http://127.0.0.1:8000 ` , which will make your browser send a request to your application. It will then send a JSON response with the following:
fastapi_security_advanced_user_guide/fastapipythonwebapis_115_0.txt
Python
fastapi_security_advanced_user_guide/anintroductiontopyth_74_0.txt
](https://medium.com/about?autoplay=1&source=post_page----- fb68d8861fad--------------------------------)
fastapi_security_advanced_user_guide/fastapipythonwebapis_275_0.txt
Python
fastapi_security_advanced_user_guide/fastapipythonwebapis_257_0.txt
[ ![JSON Schema for pydantic models is included in API docs UI](https://files.realpython.com/media/fastapi-body-image01.cbf75d4cdb50.png) ](https://files.realpython.com/media/fastapi-body-image01.cbf75d4cdb50.png)
fastapi_security_advanced_user_guide/configuration_87_0.txt
* [ About Swagger ](/about/) * [ Blog ](/blog/) * [ Support ](/support/) * [ News ](/blog/news/) * [ Contact Us ](https://smartbear.com/contact-us/)
fastapi_security_advanced_user_guide/anintroductiontopyth_20_0.txt
In this Python tutorial, you will learn about FastAPI that a Web framework for developing RESTful APIs in Python.
fastapi_security_advanced_user_guide/fastapipythonwebapis_117_0.txt
from fastapi import FastAPI
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_1_5.txt
"parameterize" our dependency, that now has ` "bar" ` inside of it, as the attribute ` checker.fixed_content ` . ## Use the instance as a dependency ¶ Then, we could use this ` checker ` in a ` Depends(checker) ` , instead of ` Depends(FixedContentQueryChecker) ` , because the dependency is the instance, ` checker...
fastapi_security_advanced_user_guide/fastapipythonwebapis_80_0.txt
The browser-based user interface documenting your API is provided and integrated by default. You don’t have to do anything else to take advantage of it with FastAPI.
fastapi_security_advanced_user_guide/configuration_98_0.txt
* [ Careers ](https://smartbear.com/company/careers/) |
fastapi_security_advanced_user_guide/fastapipythonwebapis_212_0.txt
Copied!
fastapi_security_advanced_user_guide/anintroductiontopyth_76_0.txt
](https://medium.com/jobs-at-medium/work-at- medium-959d1a85284e?source=post_page----- fb68d8861fad--------------------------------)
fastapi_security_advanced_user_guide/fastapipythonwebapis_159_0.txt
app = FastAPI()
fastapi_security_advanced_user_guide/fastapipythonwebapis_34_0.txt
* Use **path parameters** to get a unique URL path per item * Receive JSON data in your requests using **pydantic** * Use API best practices, including **validation** , **serialization** , and **documentation** * Continue learning about FastAPI for **your use cases**
fastapi_security_advanced_user_guide/fastapipythonwebapis_273_0.txt
### Use the pydantic Model
fastapi_security_advanced_user_guide/fastapipythonwebapis_57_0.txt
app = FastAPI()
fastapi_security_advanced_user_guide/fastapipythonwebapis_65_0.txt
$ uvicorn main:app --reload
fastapi_security_advanced_user_guide/fastapi_security_1_2.txt
/) * [ Testing a Database ](../../advanced/testing-database/) * [ Async Tests ](../../advanced/async-tests/) * [ Settings and Environment Variables ](../../advanced/settings/) * [ OpenAPI Callbacks ](../../advanced/openapi-callbacks/) * [ OpenAPI Webhooks ](../../advanced/openapi-webh...
fastapi_security_advanced_user_guide/configuration_86_0.txt
Swagger
fastapi_security_advanced_user_guide/fastapi_security_11_0.txt
Skip to content [ Follow **@fastapi** on **Twitter** to stay updated ](https://twitter.com/fastapi) [ Subscribe to the **FastAPI and friends** newsletter 🎉 ](https://fastapi.tiangolo.com/newsletter/) [ You can now sponsor **FastAPI** 🍰 ](https://github.com/sponsors/tiangolo) [ sponsor ![](/img/sponsors/cryptapi-...
fastapi_security_advanced_user_guide/anintroductiontopyth_55_0.txt
[ ](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fvote%2Fp%2Ffb68d8861fad&operation=register&redirect=https%3A%2F%2Fayselaydin.medium.com%2Fan- introduction-to-python-fastapi-swagger-ui- fb68d8861fad&user=Aysel+Aydin&userId=8f989c1f1548&source=-----fb68d8861fad ---------------------clap_footer---...
fastapi_security_advanced_user_guide/thebenefits_24_0.txt
In conclusion, Swagger and OpenAPI are valuable tools for building APIs with FastAPI. They allow you to easily design, document, and test your API, ensuring that it is well-designed and working correctly. By using Swagger and OpenAPI with FastAPI, you can take advantage of their many features to make your API developme...
fastapi_security_advanced_user_guide/fastapipythonwebapis_133_0.txt
@app.get("/") async def root(): return {"message": "Hello World"}
fastapi_security_advanced_user_guide/fastapipythonwebapis_131_0.txt
from fastapi import FastAPI
fastapi_security_advanced_user_guide/fastapipythonwebapis_31_0.txt
Creating APIs, or **application programming interfaces** , is an important part of making your software accessible to a broad range of users. In this tutorial, you will learn the main concepts of **FastAPI** and how to use it to quickly create web APIs that implement best practices by default.
fastapi_security_advanced_user_guide/fastapipythonwebapis_95_0.txt
` FastAPI ` is a [ Python class ](https://realpython.com/python-classes/) that provides all the functionality for your API.