id stringlengths 16 145 | text stringlengths 1 179k | title stringclasses 1
value |
|---|---|---|
fastapi_security_advanced_user_guide/fastapipythonwebapis_226_0.txt | from typing import Optional | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_262_0.txt | [ Remove ads ](/account/join/) | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_354_0.txt | Recommended Video Course: [ Python REST APIs With FastAPI ](/courses/python-
rest-apis-with-fastapi/) | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_301_0.txt | * [ Query parameters ](https://fastapi.tiangolo.com/tutorial/query-params/) to customize a request
* [ Dependency injection ](https://fastapi.tiangolo.com/tutorial/dependencies/) to handle reusable logic for permissions, database sessions, and others
* [ Security utilities ](https://fastapi.tiangolo.com/tutorial/securi... | |
fastapi_security_advanced_user_guide/anintroductiontopyth_29_0.txt | **Create a First API** | |
fastapi_security_advanced_user_guide/configuration_106_0.txt | * +61 391929960 AUS | |
fastapi_security_advanced_user_guide/configuration_34_0.txt | ##### Core | |
fastapi_security_advanced_user_guide/fastapi_security_8_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 
def magic_data_reader(raw_body: bytes):
return {
"size": len(raw_body),
"content": {
"name": "Maaaagic",
"price": 42,
"description": "Just kiddin', no magic here. ✨",
... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_243_0.txt | Python | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_85_0.txt | As FastAPI is based on standards like OpenAPI, there are many alternative ways
to show the API documentation. FastAPI provides these two alternatives by
default. | |
fastapi_security_advanced_user_guide/anintroductiontopyth_32_0.txt | @app.get("/")
async def my_first_get_api():
return {"message":"First FastAPI example"} | |
fastapi_security_advanced_user_guide/configuration_2_0.txt | [  API Design ](/solutions/api-
design/ "API Design") [  API
Development ](/solutions/api-development "API Development") [
 API Documentation
](/solutions/api-documentation/ "API D... | |
fastapi_security_advanced_user_guide/thebenefits_7_0.txt | Swagger UI for generating API documentation | |
fastapi_security_advanced_user_guide/fastapi_security_7_4.txt | he code for the tests just like before.
## Testing: extended example ¶
Now let's extend this example and add more details to see how to test
different parts.
### Extended **FastAPI** app file ¶
Let's continue with the same file structure as before:
.
├── app
│ ├── __init__.py
│ ├─... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_9_0.txt | 🐍 Python Tricks 💌 | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_170_0.txt | Python | |
fastapi_security_advanced_user_guide/fastapi_security_2_0.txt | [ 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  ](htt... | |
fastapi_security_advanced_user_guide/fastapi_security_11_4.txt | b = {
"johndoe": {
"username": "johndoe",
"full_name": "John Doe",
"email": "johndoe@example.com",
"hashed_password": "fakehashedsecret",
"disabled": False,
},
"alice": {
"username": "alice",
"full_name": "Alice ... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_45_0.txt | The first step is to install FastAPI and [ Uvicorn
](https://www.uvicorn.org/#introduction) using [ ` pip `
](https://realpython.com/what-is-pip/) : | |
fastapi_security_advanced_user_guide/configuration_105_0.txt | * +353 91 398300 EUR
| | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_308_0.txt | Mark as Completed | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_256_0.txt | The JSON Schemas of your pydantic models will be part of the OpenAPI generated
for your application and will be shown in the interactive API documentation: | |
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_5_4.txt | async def create_item(item: Item):
"""
Create an item with all the information:
- **name**: each item must have a name
- **description**: a long description
- **price**: required
- **tax**: if the item doesn't have tax, you can omit this
- **tags**: a set o... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_350_0.txt | * * * | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_344_0.txt | What Do You Think? | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_15_0.txt | [ api ](/tutorials/api/) [ best-practices ](/tutorials/best-practices/) [
career ](/tutorials/career/) [ community ](/tutorials/community/) [ databases
](/tutorials/databases/) [ data-science ](/tutorials/data-science/) [ data-
structures ](/tutorials/data-structures/) [ data-viz ](/tutorials/data-viz/) [
devops ](/tut... | |
fastapi_security_advanced_user_guide/thebenefits_41_0.txt | Archive
·
Privacy policy
·
Terms
Write on Hashnode
Powered by Hashnode - Home for tech writers and readers | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_182_0.txt |
Copied! | |
fastapi_security_advanced_user_guide/configuration_96_0.txt | * [ TestLeft ](https://smartbear.com/product/testleft/overview/?utm_medium=referral&utm_source=swagger.io&utm_campaign=footer)
* [ VisualTest ](https://smartbear.com/product/visualtest/?utm_medium=referral&utm_source=swagger.io&utm_campaign=footer)
* [ Zephyr ](https://smartbear.com/test-management/zephyr?utm_medium=re... | |
fastapi_security_advanced_user_guide/fastapi_security_11_18.txt | )
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 username or password")
user = UserInDB(**user_dict)
hashed_password = ... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_297_0.txt | [ Remove ads ](/account/join/) | |
fastapi_security_advanced_user_guide/thebenefits_4_0.txt | Swagger and OpenAPI are popular tools for designing, building, and documenting APIs. | |
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_2_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/coo... | |
fastapi_security_advanced_user_guide/configuration_69_0.txt | DEFAULT_MODELS_EXPAND_DEPTH="5"
DEFAULT_MODEL_EXPAND_DEPTH="7" | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_126_0.txt | FastAPI doesn’t enforce any specific meaning. The information here is
presented as a guideline, not a requirement. | |
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_7_3.txt | , Design and Future ](../../history-design-future/)
* [ Benchmarks ](../../benchmarks/)
* [ Help ](../../help/)
Help
* [ Help FastAPI - Get Help ](../../help-fastapi/)
* [ Development - Contributing ](../../contributing/)
* [ Release Notes ](../../release-notes/)
Table of contents
* Use a ` ... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_248_0.txt | app = FastAPI() | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_326_0.txt | ](/team/bzaczynski/) | |
fastapi_security_advanced_user_guide/configuration_1_0.txt | * Learn | |
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_0_2.txt | ../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-tests/)
* [ Set... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_351_0.txt | Looking for a real-time conversation? Visit the [ Real Python Community Chat
](/community/) or join the next [ “Office Hours” Live Q&A Session ](/office-
hours/) . Happy Pythoning! | |
fastapi_security_advanced_user_guide/configuration_92_0.txt | Explore SmartBear Products | |
fastapi_security_advanced_user_guide/configuration_72_0.txt | Example: | |
fastapi_security_advanced_user_guide/fastapi_security_2_3.txt | ://github.com/tiangolo/fastapi "github.com") [
](https://discord.gg/VQjSZaeJmf "discord.gg") [ ](https://twitter.com/fastapi
"twitter.com") [ ](https://www.linkedin.com/in/tiangolo "www.linkedin.com") [
](https://dev.to/tiangolo "dev.to") [ ](https://medium.com/@tiangolo
"medium.com") [ ](https://tiangolo.com "tiangolo... | |
fastapi_security_advanced_user_guide/anintroductiontopyth_26_0.txt | pip install fastapi | |
fastapi_security_advanced_user_guide/fastapi_security_11_13.txt | e] = None
class UserInDB(User):
hashed_password: str
def get_user(db, username: str):
if username in db:
user_dict = db[username]
return UserInDB(**user_dict)
def fake_decode_token(token):
# This doesn't provide any security at al... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_1_0.txt | * [ Start Here ](/start-here/)
* Learn Python | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_272_0.txt | If you use PyCharm as your editor, then you can use the [ pydantic PyCharm
plugin ](https://github.com/koxudaxi/pydantic-pycharm-plugin/) to improve your
editor support. And if you use VS Code, then you will get the best developer
experience with [ Pylance
](https://marketplace.visualstudio.com/items?itemName=ms-python... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_67_0.txt |
Copied! | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_323_0.txt | ](/team/asantos/) | |
fastapi_security_advanced_user_guide/fastapi_security_11_2.txt | ses/)
* [ Advanced Middleware ](../../../advanced/middleware/)
* [ Sub Applications - Mounts ](../../../advanced/sub-applications/)
* [ Behind a Proxy ](../../../advanced/behind-a-proxy/)
* [ Templates ](../../../advanced/templates/)
* [ WebSockets ](../../../advanced/websockets/)
... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_231_0.txt |
Copied! | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_317_0.txt | Hey! 👋 I'm Sebastián (tiangolo), I'm the creator of FastAPI, Typer, and other
open source tools. I'm commonly building APIs and tools for data/ML systems. 🤖 | |
fastapi_security_advanced_user_guide/fastapi_security_11_24.txt | il": "Inactive user"
}
## Recap ¶
You now have the tools to implement a complete security system based on `
username ` and ` password ` for your API.
Using these tools, you can make the security system compatible with any
database and with any user or data model.
The only detail missing is that it is not... | |
fastapi_security_advanced_user_guide/configuration_60_0.txt | Example: | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_349_0.txt | **Commenting Tips:** The most useful comments are those written with the goal
of learning from or helping out other students. [ Get tips for asking good
questions ](https://realpython.com/python-beginner-tips/#tip-9-ask-good-
questions) and [ get answers to common questions in our support portal
](https://support.realp... | |
fastapi_security_advanced_user_guide/anintroductiontopyth_40_0.txt | Check out my Github repository for more example👇👇👇 | |
fastapi_security_advanced_user_guide/anintroductiontopyth_9_0.txt | # An Introduction to Python FastAPI & Swagger UI | |
fastapi_security_advanced_user_guide/fastapi_security_4_1.txt | ields ](../../body-fields/)
* [ Body - Nested Models ](../../body-nested-models/)
* [ Declare Request Example Data ](../../schema-extra-example/)
* [ Extra Data Types ](../../extra-data-types/)
* [ Cookie Parameters ](../../cookie-params/)
* [ Header Parameters ](../../header-params/... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_319_0.txt | * * * | |
fastapi_security_advanced_user_guide/anintroductiontopyth_37_0.txt | Expand the “ **My First Get Api** ” | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_237_0.txt | In this case, since ` description ` and ` tax ` are optional because they have
a default value of ` None ` , this JSON object would also be valid: | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_183_0.txt | Notice that the value your function received and then returned is ` 3 ` ,
which is a Python ` int ` , not a string ( ` "3" ` ). So, with that type
declaration, FastAPI gives you automatic **request parsing** . | |
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_9_3.txt | istory-design-future/)
* [ Benchmarks ](../../benchmarks/)
* [ Help ](../../help/)
Help
* [ Help FastAPI - Get Help ](../../help-fastapi/)
* [ Development - Contributing ](../../contributing/)
* [ Release Notes ](../../release-notes/)
Table of contents
* Use case
* Use a ` Response ` param... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_158_0.txt | from fastapi import FastAPI | |
fastapi_security_advanced_user_guide/configuration_40_0.txt | Parameter name | Docker variable | Description
---|---|---
` pluginLoadType ` | _Unavailable_ | ` String=["legacy", "chain"] ` .
Control behavior of plugins when targeting the same component with
wrapComponent.
\- ` legacy ` (default) : last plugin takes precedence over the others
\- ` chain ` : chain wrapCompone... | |
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_5_1.txt | tiple-params/)
* [ 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 ](../.... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_98_0.txt | # main.py | |
fastapi_security_advanced_user_guide/fastapi_security_11_1.txt | * [ Body - Fields ](../../body-fields/)
* [ Body - Nested Models ](../../body-nested-models/)
* [ Declare Request Example Data ](../../schema-extra-example/)
* [ Extra Data Types ](../../extra-data-types/)
* [ Cookie Parameters ](../../cookie-params/)
* [ Header Parameters ](../.... | |
fastapi_security_advanced_user_guide/fastapi_advanced_user_guide_0_3.txt | piration and Comparisons ](../../alternatives/)
* [ History, Design and Future ](../../history-design-future/)
* [ Benchmarks ](../../benchmarks/)
* [ Help ](../../help/)
Help
* [ Help FastAPI - Get Help ](../../help-fastapi/)
* [ Development - Contributing ](../../contributing/)
* [ Release... | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_315_0.txt | About **Sebastián Ramírez** | |
fastapi_security_advanced_user_guide/anintroductiontopyth_69_0.txt | Help | |
fastapi_security_advanced_user_guide/thebenefits_22_0.txt | @app.post("/items/")
def create_item(item: Item):
return item
In this example, we define a request model called Item using a pydantic model. We then use this model as the parameter for a POST endpoint and return the item in the response. FastAPI will automatically validate the request body to ensure that it contains a ... | |
fastapi_security_advanced_user_guide/fastapi_security_4_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  | |
fastapi_security_advanced_user_guide/anintroductiontopyth_15_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/configuration_110_0.txt | * [ Site Map ](https://swagger.io/site-map/)
| | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_245_0.txt | from typing import Optional | |
fastapi_security_advanced_user_guide/configuration_30_0.txt | Parameters with dots in their names are single strings used to organize
subordinate parameters, and are not indicative of a nested structure. | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_218_0.txt | Nevertheless, using a ` GET ` request is supported by FastAPI, though only for
very complex or extreme use cases. As it is discouraged, the interactive
documentation with Swagger UI won’t show the documentation for the body when
using ` GET ` , and proxies in the middle might not support it. | |
fastapi_security_advanced_user_guide/fastapi_security_1_4.txt | the background ( ` write_notification ` ).
* Any sequence of arguments that should be passed to the task function in order ( ` email ` ).
* Any keyword arguments that should be passed to the task function ( ` message="some notification" ` ).
## Dependency Injection ¶
Using ` BackgroundTasks ` also works with... | |
fastapi_security_advanced_user_guide/anintroductiontopyth_73_0.txt | About | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_22_0.txt |  | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_123_0.txt | * ` @app.post() `
* ` @app.put() `
* ` @app.delete() `
* ` @app.options() `
* ` @app.head() `
* ` @app.patch() `
* ` @app.trace() ` | |
fastapi_security_advanced_user_guide/thebenefits_11_0.txt | To use Swagger and OpenAPI with FastAPI, you simply need to add a few lines of code to your FastAPI app. Here's an example of how to define a basic "Hello, World!" API using FastAPI and generating API documentation using Swagger UI: | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_240_0.txt |
Copied! | |
fastapi_security_advanced_user_guide/fastapipythonwebapis_214_0.txt | ## Request Body: Receiving JSON Data |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.