![Code Collider](/img/default-banner.jpg)
- Видео 25
- Просмотров 41 914
Code Collider
Индия
Добавлен 25 ноя 2023
I make intermediate and advanced backend software development related videos.
Best Library for MongoDB Queries in Your FastAPI Application
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
async mongodb with fastapi
motor mongodb fastapi
fastapi mongodb connection string
fastapi mongodb environment variables
fastapi mongodb crud operations async
iterate through mongodb cursor async fastapi
difference between pymongo and motor python
fastapi mongodb blocking event loop
how to use motor in fastapi
best way to ...
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
async mongodb with fastapi
motor mongodb fastapi
fastapi mongodb connection string
fastapi mongodb environment variables
fastapi mongodb crud operations async
iterate through mongodb cursor async fastapi
difference between pymongo and motor python
fastapi mongodb blocking event loop
how to use motor in fastapi
best way to ...
Просмотров: 252
Видео
Every FastAPI File Upload Method | Working and Best Practices!
Просмотров 2,7 тыс.2 месяца назад
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
Просмотров 5553 месяца назад
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
Просмотров 6273 месяца назад
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
Просмотров 9204 месяца назад
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
Просмотров 10 тыс.4 месяца назад
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
Просмотров 20 тыс.4 месяца назад
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
Просмотров 1724 месяца назад
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
Просмотров 9924 месяца назад
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 тыс.5 месяцев назад
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
Просмотров 765 месяцев назад
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
Просмотров 1685 месяцев назад
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
Просмотров 2565 месяцев назад
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
Просмотров 126 месяцев назад
In this video, we delve into an efficient algorithm for calculating exponents, optimizing the process and significantly reducing time complexity. The problem at hand is to compute x raised to the power n, where x=2 and n=10 serves as our illustrative example. The conventional approach involves a loop that multiplies x with the answer variable n times, resulting in a time complexity of O(n). How...
Search in a Sorted 2D Matrix | Everything You Need To Know | DSA Revision Series | Python
Просмотров 186 месяцев назад
In this video, we delve into the problem of efficiently finding a given element in a sorted 2D matrix. We explore the concept of a sorted 2D matrix, defining the conditions it must meet, and then present two solutions to the problem. 🤔 Problem Description: The challenge is to locate a specific element in a 2D matrix that satisfies the conditions of having rows arranged in ascending order and th...
Count Inversions In An Array | Python DSA Revision Series
Просмотров 5196 месяцев назад
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
Просмотров 426 месяцев назад
Three Ways to Find Duplicate Number in Array of N 1 Integers | Python DSA Revision Series
DSA Interview Revision | 3 Commonly Asked Problems
Просмотров 217 месяцев назад
DSA Interview Revision | 3 Commonly Asked Problems
3 Popular Interview Problems in 5 Minutes | Python DSA Revision Series
Просмотров 157 месяцев назад
3 Popular Interview Problems in 5 Minutes | Python DSA Revision Series
3 Popular Interview Problems in 4 Minutes | DSA Revision Series
Просмотров 267 месяцев назад
3 Popular Interview Problems in 4 Minutes | DSA Revision Series
Stock Market Portfolio Construction Using Python | Introduction to PyPortfolioOpt
Просмотров 1347 месяцев назад
Stock Market Portfolio Construction Using Python | Introduction to PyPortfolioOpt
Overriding Dependencies During Testing Fastapi Application | Tutorial 4
Просмотров 1047 месяцев назад
Overriding Dependencies During Testing Fastapi Application | Tutorial 4
How to Execute Fastapi Startup Event in Test | Tutorial 3
Просмотров 958 месяцев назад
How to Execute Fastapi Startup Event in Test | Tutorial 3
Fastapi Endpoints Testing with Unittest | Tutorial 2
Просмотров 1108 месяцев назад
Fastapi Endpoints Testing with Unittest | Tutorial 2
Fastapi endpoints testing with pytest | Tutorial 1
Просмотров 6788 месяцев назад
Fastapi endpoints testing with pytest | Tutorial 1
Excellent…can it create mock test involving AWS services?
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.
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.
got any benchmarks?
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.
oh, sorry, that was a hook for further story
Maybe better practice to read chunks from file is async for?
Great video, thanks for sharing
Clearly explained!! Thank you
Well fastapi ( fun get ( ))
Beautifully explained!
Nice!
Nice explanation. Concise and to the point.
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.
This is a fastAPI video
It's actually both. End of argument
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.
Great explanation, you should create more videos bro...
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?
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.
@@codecollider Yes you are right. I tried from different browsers and it worked. Strange though. Thanks
Great video. Short and to the point. Subscribed.
Great video. Thanks
this should boom i love ur channel
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?
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...
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.
@@Praise-rs4mc thanks alot, I will give it a try.
Crisp and clear ❤
Great video. Thanks
Thanks. ❤
great video
boooozi txeq
Why not just return condition?
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.
Thnx
I always upload with just an post.
very nice video, thanks!
can you make fastapi how run under the hood and how @app.exception_handler work Thanks awesome contentent
Thanks for clearing this concept.
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
Local, Enclosing, Global, and Built-in scopes for those playing along at home
Your videos are the best. No bs, just facts.
Great knowledgable video
thx bro! so useful material, keep going
very well explanation.
thank you!
dont we have to enable the 68 no line? "app = Fastapi(lifespan=lifespan)" ?
Yes you have to uncomment that line if you are using lifespan, forget to tell in the video.
Hello I am not able to run Pynguin. I tryed your approach and got this error: (base) seva@air-von-seva Pynguin_input % pynguin --project-path . --module-name test_example_2 --output-path . Traceback (most recent call last): File "/Users/seva/anaconda3/bin/pynguin", line 5, in <module> from pynguin.cli import main File "/Users/seva/anaconda3/lib/python3.11/site-packages/pynguin/__init__.py", line 9, in <module> import pynguin.generator as gen File "/Users/seva/anaconda3/lib/python3.11/site-packages/pynguin/generator.py", line 31, in <module> import pynguin.analyses.seeding as seeding # pylint: disable=consider-using-from-import ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/seva/anaconda3/lib/python3.11/site-packages/pynguin/analyses/seeding.py", line 25, in <module> import pynguin.ga.testcasechromosome as tcc File "/Users/seva/anaconda3/lib/python3.11/site-packages/pynguin/ga/testcasechromosome.py", line 13, in <module> import pynguin.ga.chromosome as chrom File "/Users/seva/anaconda3/lib/python3.11/site-packages/pynguin/ga/chromosome.py", line 13, in <module> import pynguin.ga.computations as ff File "/Users/seva/anaconda3/lib/python3.11/site-packages/pynguin/ga/computations.py", line 17, in <module> from pynguin.testcase.execution import ExecutionTrace File "/Users/seva/anaconda3/lib/python3.11/site-packages/pynguin/testcase/execution.py", line 425, in <module> class ExecutionTracer: File "/Users/seva/anaconda3/lib/python3.11/site-packages/pynguin/testcase/execution.py", line 460, in ExecutionTracer Compare.IN: lambda val1, val2: ( ^^^^^^^^^^ File "/Users/seva/anaconda3/lib/python3.11/enum.py", line 784, in __getattr__ raise AttributeError(name) from None AttributeError: IN
❤
You must learn about the Dynaconf library
Great content brother Quick Modification: sync router is Concurrency not Parallelism. In python parallelism is achieved only by multiprocessing
Great video, but I think it’s important to mention that multi-threading in Python is not parallel
Multi processing*
@@bakasenpaidesu Actually you are wrong; multiprocessing is parallel because Python spawns an entirely new process with an entirely new interpreter.
Multi threading in python is technically also parallel programming whenever a thread releases the GIL, such as during time.sleep or open calls. In those specific instances, there can be two (or more) threads truly executing in parallel in the same python process, because one thread is waiting for the results of a system call, during which time it releases the GIL since reference counts don’t need to be updated, allowing another thread to acquire the GIL and execute a piece of code in parallel.
On this topic also: check out the beta of. Python 3.13! There is a flag that can be passed when launching python that removes the GIL, allowing truly parallelized execution with just threads. Been playing around with asyncio and concurrent.futures.ThreadPoolExecutor -> noticeable speed up. Shame that c-extension based libraries like numpy are unusable with this setting
@@benshapiro9731 This is called concurrency, not parallelism. Parallelism is when two or more tasks can run simultaneously, using the CPU, without waiting for I/O-bound operations. While the GIL doesn't prevent Python from switching context between threads waiting for I/O-bound operations, this is still considered concurrency, not parallelism.
Your best practices videos are great. Keep going. ❤
Great videos
thank you!
Keep it up bro...😊
OMG! This is so helpful and a great video. Thank you and please post more videos like this!
Hello! Thank you for the video! Could you tell me how to measure the request (in your video it’s about 300ms)? Using a decorator? If so, I tried it, but it didn’t help, because time information is simply not displayed in the logs. I would like this information to be absorbed and for me to see a clear difference in the use of reguess and nttpx. I can’t leave a comment with a link to pastebin because youtube deletes such comments
I mentioned 300 milliseconds (ms) for external API calls, but that's a general idea based on what I've seen. The actual time can vary. No matter if you use requests or httpx, the external API itself will take some time (usually hundreds of milliseconds) to respond. We can't control that wait time. Focus on not blocking your app: The key difference is how httpx.AsyncClient handles waiting. With requests, your application grinds to a halt while it waits for the API response. This can be bad if your app needs to do other things. httpx.AsyncClient lets your application keep working even while waiting for the API. This is because it uses an asynchronous approach, which means it can juggle multiple tasks at once.
@@codecollider Thank you for answer!
@@codecollider How is it different from multi-threading then?
Look at using a middleware to measure the elapsed time of a request. It always frightened me to even think about using middleware, probably due to CORS headaches, but when I finally did this exact use case, it turned out to be dirt simple.
@@dixon1e Did it make any difference to your run time though. With this simple example I don't think it would make any difference because it doesnt have any other task to execute while waiting for the response?