Code Collider
Code Collider
  • 27
  • 57 415
Inside Fastapi | How it Uses Type Hints for Validation
In this video, we'll dive deep into how FastAPI uses Python type hints and Pydantic to perform input validation automatically. You'll learn how FastAPI reads function signatures using the inspect module and how it applies type validation using Pydantic's TypeAdapter. We'll walk through examples, explaining the process step by step, including how FastAPI handles path, query, and body parameters. By the end, you'll understand how FastAPI extracts type information, validates incoming requests, and returns detailed error messages for invalid data. Whether you're building APIs with FastAPI or want to improve your Python validation skills, this tutorial covers it all!
Topics covered:
Python type hints for validation
FastAPI request handling and validation
Pydantic's TypeAdapter usage
inspect module for function signatures
Perfect for developers learning FastAPI, Python validation, and building robust APIs!
Search Queries:
FastAPI type hint validation
How does FastAPI use Python type hints?
FastAPI input validation with Pydantic
FastAPI input validation example
Python type hints for API validation
Using Pydantic for validation in FastAPI
FastAPI function argument validation tutorial
How to validate request data in FastAPI
Understanding FastAPI and Python type hints
FastAPI validation error handling
FastAPI Pydantic TypeAdapter explained
How FastAPI validates request parameters
Using inspect.signature in FastAPI
FastAPI automatic input validation
Python inspect module for API validation
FastAPI request data validation with Pydantic
FastAPI tutorial on type hint validation
How to handle invalid data in FastAPI
FastAPI route validation with Pydantic models
FastAPI type hint error handling
#FastAPI #Python #Pydantic #WebDevelopment #API #BackendDevelopment #TypeHints #PythonTips #PythonTutorial #APIDevelopment #APITutorial #Coding #Programming #SoftwareDevelopment #LearnPython #DevTips #PythonValidation #TechTutorial #FullStackDevelopment #FastAPITutorial
Переглядів: 365

Відео

Deploy Static Website for FREE on GitHub Pages | Custom Domain, HTTPS, Fix Broken Links!
Переглядів 171Місяць тому
Introduction: In this video, I’ll walk you through how to deploy a static website for FREE using GitHub Pages. We’ll cover everything from uploading your files, setting up a custom domain, enabling HTTPS, and fixing common issues like broken links that you might face when deploying sites with GitHub Pages. This is a beginner-friendly, step-by-step guide that will have your site live in no time!...
Best Library for MongoDB Queries in Your FastAPI Application
Переглядів 3183 місяці тому
Git Repository: github.com/AbdullahSaquib/fastapi-mongodb-template Timestamps: 0:00 Introduction 0:35 Getting MongoDB Connection String 0:56 ENV File 1:26 Creating a Config File with Pydantic 2:13 Connecting to MongoDB with Motor 3:03 Performing CRUD Operations in FastAPI 3:37 Working with MongoDB Cursors Asynchronously Search Queries: fastapi mongodb integration fastapi connect to mongodb asyn...
Every FastAPI File Upload Method | Working and Best Practices!
Переглядів 4,5 тис.5 місяців тому
Request Stream Handling Reference: stackoverflow.com/questions/73442335/how-to-upload-a-large-file-≥3gb-to-fastapi-backend Offical Documentation: fastapi.tiangolo.com/tutorial/request-files/ Learn how to handle file uploads in FastAPI effectively! This video dives deep into various techniques for file uploads in FastAPI, including: UploadFile Class: Mastering the built-in UploadFile class for e...
Local vs Global vs Non-Local Variables | Python Interview Question
Переглядів 6815 місяців тому
Struggling with Python variables in your interview or code? You're not alone! This video breaks down Local, Global, and NonLocal variables in Python with clear explanations and examples. Learn the difference between them, when to use each, and avoid common mistakes that can trip you up. Master Python variables and impress your interviewer (or write cleaner code) in no time! Search Queries: pyth...
How to VALIDATE Environment Variables in Python Web App | FastAPI
Переглядів 8846 місяців тому
Using os.getenv can be a pain, forcing you to handle missing variables, type conversions, and custom validations. This video will show you a much better way using Pydantic Base Settings. Learn how to: Effortlessly define and validate environment variables (like port numbers!) Ensure your variables are of the correct type (say goodbye to unexpected errors!) Simplify code with a clean and maintai...
Generate Unit Tests in SECONDS with Pynguin Library
Переглядів 1,1 тис.6 місяців тому
Struggling to write unit tests in Python? Want to save time and effort? ⏱️ Check out Pynguin, a library that automatically generates unit tests from your code! In this video, we explore Pynguin's features: Effortless Unit Test Creation: Generate unit tests with a single command! Broad Coverage: Pynguin aims to cover various input scenarios for comprehensive testing. Refactoring Helper: Use Pyng...
Best Practice to Make HTTP Request in FastAPI Application
Переглядів 12 тис.6 місяців тому
In this video, you'll learn how to make highly available FastAPI endpoints using asynchronous HTTP requests. We'll cover: Why standard requests library blocks the event loop Introducing httpx for asynchronous requests in FastAPI 3 Best Practices: Creating an AsyncClient with context manager (basic approach) Using a dependency for cleaner code Application-wide AsyncClient for efficiency (with tr...
How FastAPI Handles Requests Behind the Scenes
Переглядів 29 тис.6 місяців тому
Unleash the power of FastAPI! Discover how Asyncio and blocking I/O impact performance. Learn to handle requests concurrently for a blazing-fast API! In this video, we explore FastAPI's handling of concurrent requests. We'll compare Asyncio vs Blocking methods and see how normal functions differ. Understand when to use each approach for optimal performance. Optimize your FastAPI application and...
Straight to Point Introduction to FastAPI | Hindi
Переглядів 2017 місяців тому
Welcome to our Beginner Introduction to FastAPI tutorial! In this video, we'll guide you through the fundamentals of FastAPI, a modern, fast (high-performance), web framework for building APIs with Python. Whether you're new to web development or looking to enhance your skills, this tutorial is designed to help you get started with FastAPI. We'll begin by walking you through the installation pr...
6 Reasons Why Devin Can't Replace Human Software Engineers
Переглядів 9967 місяців тому
In this compelling video, we delve into the complex world of Artificial Intelligence (AI) and its relationship with human software engineers. While AI continues to advance at an astonishing rate, there are crucial aspects of software engineering that remain firmly within the realm of human expertise. From creativity to problem-solving, join us as we explore six compelling reasons why AI simply ...
Speed Test: Inline vs Multi-line If Else Statements in Python
Переглядів 4,2 тис.7 місяців тому
Have you ever wondered whether inline or multi-line if else statements are faster in Python? 🤔 In this video, we dive deep into this question to uncover the truth! Python inline if else vs multi line if else, Python performance comparison, Python if else statement optimization, Python bytecode analysis, Python micro-optimizations, Python code clarity, Python maintainability, Python performance ...
Find Majority Element | Element Appearing More Than N/2 Times | DSA Revision Series | Python
Переглядів 1957 місяців тому
Are you struggling with finding the majority element in an array efficiently? Look no further! In this video, we dive deep into solving the majority element problem using various approaches, focusing on the efficient Moore's Voting Algorithm. 🔍 Problem Covered: How to find the majority element in an array. Different approaches to solve the majority element problem. Understanding the Moore's Vot...
How I Made Image Editing Website Using ChatGPT | Chatgpt for Coding
Переглядів 1838 місяців тому
In this tutorial, we dive into creating a basic image editor using ChatGPT. Follow along as we implement common features like rotation, flipping, cropping, resizing, and image quality control. Have you ever wanted to create your own image editor? Wondering how to leverage ChatGPT for such a task? Join us as we explore step-by-step how to build one from scratch. 🔍 Key Questions: How to make a ba...
How I Created Images to PDF Converter Website Using Chatgpt | Chatgpt for Coding
Переглядів 4698 місяців тому
Are you looking to create your own Images to PDF converter with the flexibility to rearrange image order? In this tutorial, we'll walk through the process step by step. We start by generating HTML, CSS, and JavaScript code using ChatGPT. We'll tackle common issues like incorrect rendering and an extra empty page in the PDF. Along the way, we'll ask ChatGPT to fix these issues and enhance our co...
DSA Interview | Implement Power Function | Python DSA Interview Revision Series
Переглядів 148 місяців тому
DSA Interview | Implement Power Function | Python DSA Interview Revision Series
Search in a Sorted 2D Matrix | Everything You Need To Know | DSA Revision Series | Python
Переглядів 268 місяців тому
Search in a Sorted 2D Matrix | Everything You Need To Know | DSA Revision Series | Python
Count Inversions In An Array | Python DSA Revision Series
Переглядів 7679 місяців тому
Count Inversions In An Array | Python DSA Revision Series
Three Ways to Find Duplicate Number in Array of N+1 Integers | Python DSA Revision Series
Переглядів 499 місяців тому
Three Ways to Find Duplicate Number in Array of N 1 Integers | Python DSA Revision Series
DSA Interview Revision | 3 Commonly Asked Problems
Переглядів 249 місяців тому
DSA Interview Revision | 3 Commonly Asked Problems
3 Popular Interview Problems in 5 Minutes | Python DSA Revision Series
Переглядів 169 місяців тому
3 Popular Interview Problems in 5 Minutes | Python DSA Revision Series
3 Popular Interview Problems in 4 Minutes | DSA Revision Series
Переглядів 279 місяців тому
3 Popular Interview Problems in 4 Minutes | DSA Revision Series
Stock Market Portfolio Construction Using Python | Introduction to PyPortfolioOpt
Переглядів 21410 місяців тому
Stock Market Portfolio Construction Using Python | Introduction to PyPortfolioOpt
Overriding Dependencies During Testing Fastapi Application | Tutorial 4
Переглядів 14110 місяців тому
Overriding Dependencies During Testing Fastapi Application | Tutorial 4
How to Execute Fastapi Startup Event in Test | Tutorial 3
Переглядів 11010 місяців тому
How to Execute Fastapi Startup Event in Test | Tutorial 3
Fastapi Endpoints Testing with Unittest | Tutorial 2
Переглядів 17510 місяців тому
Fastapi Endpoints Testing with Unittest | Tutorial 2
Fastapi endpoints testing with pytest | Tutorial 1
Переглядів 91211 місяців тому
Fastapi endpoints testing with pytest | Tutorial 1

КОМЕНТАРІ

  • @sarvesh6785
    @sarvesh6785 6 днів тому

    Amazing Video brother. You solved my issue.

  • @henilshah.
    @henilshah. 8 днів тому

    coooooooooooooooooooooooooooooooooolllllllllll 🤟thanks man

  • @kc12394
    @kc12394 13 днів тому

    Cool video. I would like to add that relative file path also works for your links.

  • @fhuadbalogun2997
    @fhuadbalogun2997 25 днів тому

    Thank you very much for this.

  • @joelstevick1533
    @joelstevick1533 Місяць тому

    Nice video!

  • @hyakuheli
    @hyakuheli Місяць тому

    what happens if the server is created with multiple processes (for multiple cores) with uvicorn main:app --workers 4. The first 4 clients are given a new process? or it can be either a process or another thread if a thread is in a non-blocking task? and what happens when there are more than 4 clients at the same time in this case? the new clients are assigned to threads randomly across the 4 processes?

  • @PriyankRupareliya
    @PriyankRupareliya Місяць тому

    This is very valuable content. New job, starting to work on FastAPI. The whole python paradigm is new for me. This video helped clear one of the most critical concept for me. Thanks brother.

  • @adityahpatel
    @adityahpatel Місяць тому

    2 and 3 look the same. hello of each is printed first then bye from each. how is 2 and 3 different? its not explained crystal clearly

  • @RaadLearn
    @RaadLearn Місяць тому

    Thanks man.

  • @ArulMuruganAS
    @ArulMuruganAS Місяць тому

    its working as explained in unix but for some reason its a different behavior in windows

  • @harikrishnanb7273
    @harikrishnanb7273 Місяць тому

    is there a english version?

  • @startup_cult
    @startup_cult Місяць тому

    this is such an underrated video

  • @ashwinabrahamjacob525
    @ashwinabrahamjacob525 2 місяці тому

    great video

  • @diwakardayalan
    @diwakardayalan 2 місяці тому

    Excellent…can it create mock test involving AWS services?

  • @rainbowrunner1136
    @rainbowrunner1136 2 місяці тому

    Hello, great video. I am super new to python. And started using very recently for backend where its being used along with FastAPI. Can you please tell me what are some concepts/ topics which I should be aware for developing efficient code. For eg from this video, I learnt that which function runs concurrently and which doesn't. I had no idea tbh about this before. If you could spare few minutes and share some stuff which I should know it would be great.

  • @apefu
    @apefu 2 місяці тому

    I have so many questions, I am so sorry. Should you pass app to the AsyncClient() as well for the ASGI server? Also, how would the last example affect APIRouters defined in separate files? How would they reach app.client? They could have their separate lifespan function but wouldn't it be prefered to use the same object? Also, I don't know, but wouldn't it be better to use app.state.client? Oh, and what about POST requests, would you still use the Request object to reach the client? It works, but it gets messy code wise.

  • @rohit1kumar
    @rohit1kumar 3 місяці тому

    got any benchmarks?

  • @Gameplay-ps9ub
    @Gameplay-ps9ub 3 місяці тому

    Well issue with this kind of libraries imho is, that real life code is not a single module separated from everything else. It's much bigger than that and has a ton of dependencies and/or setup and tear down required. Some tests require quite a lot of fixtures and some of those fixtures are configurable as well. Conclusion is...I'd have to change manually great majority of that auto generated tests to make them any good, so I might as well right them on my own from scratch. And it doesn't support python 3.11+, so it's a big issue.

  • @НиколайРюмин-й6и
    @НиколайРюмин-й6и 3 місяці тому

    oh, sorry, that was a hook for further story

  • @НиколайРюмин-й6и
    @НиколайРюмин-й6и 3 місяці тому

    Maybe better practice to read chunks from file is async for?

  • @MakeDataUseful
    @MakeDataUseful 3 місяці тому

    Great video, thanks for sharing

  • @Shane1994322
    @Shane1994322 4 місяці тому

    Clearly explained!! Thank you

  • @badrakhariunchimeg1031
    @badrakhariunchimeg1031 4 місяці тому

    Well fastapi ( fun get ( ))

  • @PyPeak
    @PyPeak 4 місяці тому

    Beautifully explained!

  • @mattstroker3742
    @mattstroker3742 4 місяці тому

    Nice!

  • @vikranttyagiRN
    @vikranttyagiRN 4 місяці тому

    Nice explanation. Concise and to the point.

  • @oktay9784
    @oktay9784 4 місяці тому

    this is not about FastApi, its about sync functions and async functions so just dont use sync functions in async functions if sync one is takes a lot of time.

    • @MakeDataUseful
      @MakeDataUseful 3 місяці тому

      This is a fastAPI video

    • @805bluebell
      @805bluebell 3 місяці тому

      It's actually both. End of argument

  • @sticksen
    @sticksen 4 місяці тому

    My question would be how FastAPI then manages workload when it´s handed over to the worker thread. Because I can only see one worker thread running, at the same time it handles 40 'workloads' concurrently.

  • @sany2k8
    @sany2k8 4 місяці тому

    Great explanation, you should create more videos bro...

  • @arjunc5896
    @arjunc5896 4 місяці тому

    def endpoint3() is not running parallely for me as supposed to what u said in the video. Instead it is sunning one at a time. Do u know why?

    • @codecollider
      @codecollider 4 місяці тому

      I believe you are testing APIs in the browser. Sometimes, browsers like Chrome have limitations on making parallel requests to the same URL. In the video, if you look closely, I am using two different browsers to hit the same API in parallel. You can try the same approach.

    • @arjunc5896
      @arjunc5896 4 місяці тому

      @@codecollider Yes you are right. I tried from different browsers and it worked. Strange though. Thanks

  • @nitishvirtual4745
    @nitishvirtual4745 4 місяці тому

    Great video. Short and to the point. Subscribed.

  • @ChrisHalden007
    @ChrisHalden007 4 місяці тому

    Great video. Thanks

  • @ahmedelnakeeb5853
    @ahmedelnakeeb5853 4 місяці тому

    this should boom i love ur channel

  • @lwangacaleb2729
    @lwangacaleb2729 5 місяців тому

    I need some help, I want to create a fast api endpoint that calls a synchronous function that has a lot of blocking I/0 operations. But I want the endpoint function to run asynchronously so it can accept many requests at the same time. How should I do this, is there an alternative approach?

    • @Praise-rs4mc
      @Praise-rs4mc 4 місяці тому

      The only way to achieve that is to use multi-threading which I advice against.... instead, make the function asynchronous and try to find the non-blocking function for what you want to do...

    • @Praise-rs4mc
      @Praise-rs4mc 4 місяці тому

      Better still, use the run_in_threadpool function from fastapi to run the process in a different thread so that you don't block the event...better than implementing multi threading on your own.

    • @lwangacaleb2729
      @lwangacaleb2729 4 місяці тому

      @@Praise-rs4mc thanks alot, I will give it a try.

  • @shantanudas6319
    @shantanudas6319 5 місяців тому

    Crisp and clear ❤

  • @ChrisHalden007
    @ChrisHalden007 5 місяців тому

    Great video. Thanks

  • @amodsahabandu
    @amodsahabandu 5 місяців тому

    Thanks. ❤

  • @thanosaur6741
    @thanosaur6741 5 місяців тому

    great video

  • @robertavetisyan8282
    @robertavetisyan8282 5 місяців тому

    boooozi txeq

  • @richardboreiko
    @richardboreiko 5 місяців тому

    Why not just return condition?

    • @codecollider
      @codecollider 5 місяців тому

      Using `return condition` directly is more efficient when you only need to return the boolean value itself. However, the purpose of my comparison was to explore different styles of conditional statements and their performance, especially in scenarios where the if-else structure is necessary for more complex logic.

  • @suen-tech
    @suen-tech 5 місяців тому

    Thnx

  • @user-sh1fv9mm2v
    @user-sh1fv9mm2v 5 місяців тому

    I always upload with just an post.

  • @SAsquirtle
    @SAsquirtle 5 місяців тому

    very nice video, thanks!

  • @udaym4204
    @udaym4204 5 місяців тому

    can you make fastapi how run under the hood and how @app.exception_handler work Thanks awesome contentent

  • @ishaquenizamani9800
    @ishaquenizamani9800 5 місяців тому

    Thanks for clearing this concept.

  • @boringhuman9427
    @boringhuman9427 5 місяців тому

    As per LEGB rule , it is considered as enclosed variable - neither local or global but behaves as local and global within a function more specifically under decorators

    • @MakeDataUseful
      @MakeDataUseful 3 місяці тому

      Local, Enclosing, Global, and Built-in scopes for those playing along at home

  • @user-sh1fv9mm2v
    @user-sh1fv9mm2v 5 місяців тому

    Your videos are the best. No bs, just facts.

  • @MathClubfor6789
    @MathClubfor6789 5 місяців тому

    Great knowledgable video

  • @temirlllan
    @temirlllan 5 місяців тому

    thx bro! so useful material, keep going

  • @myselfriz
    @myselfriz 5 місяців тому

    very well explanation.