The video owner has disabled playback on external websites.
This video is no longer available on YouTube.
This video cannot be played right now.
Watch on YouTube
Débloquez les outils d'apprentissage IA
Inscrivez-vous pour accéder à des outils puissants qui vous aident à apprendre plus vite avec chaque vidéo.
Anatomy of a Scalable Python Project (FastAPI)
Sous-titres (534 segments)
Today I'm going to show you the anatomy
of a scalable Python project. Here you
see what my project looks like. This is
basically the setup that I use for all
my production projects. So I'm going to
talk about folder structure, config,
logging, testing, and tooling that
together forms a project that's easy to
work with and that can scale to more
complexity later on. Now, before we
start, if you want to learn how to
design software from scratch, grab my
free design guide at iron.co/design
guide. This contains a seven steps that
I use when I design new software. The
link is in the video description. Now,
when I talk about scalable, what do I
actually mean? Well, first, it should
scale with size. Basically, your code
base is going to grow over time,
assuming you're spending some time
developing new features. And as your
code base grows, you don't want to have
to do a ton of refactoring work. It
should basically be ready for scale.
Another way of think about scalability
is think about how it scales with your
team. So if you have multiple developers
that are involved in a project, you want
to make sure that the boundaries are
clear, that there are predictable places
in the code where you're going to add or
work on features. Then there's also
scalability with respect to
environments. So you want to make sure
that things like config is centralized.
Uh switching between different
environments like development, staging,
production should be uh boring in a good
way. And finally, there's also scaling
with speed. So if you have tests, they
should run fast. Uh having a local
environment should be really easy to set
up. Uh Docker works when you need it.
That kind of thing. Over the years, I've
worked on many different projects, not
just Python, but also uh TypeScript,
Java, C++, anything. And of course,
depending on the language, things are
going to be slightly different. So, what
I'll show you today is something that
works for me really well in Python. I'd
like to start with the folder structure,
which should be balanced. You want
things to be organized, but you don't
want things to be so structured in
folders that they're impossible to find.
So here's how I have set this up in this
particular project. Now there are some
folders here at the top uh which is some
caching and the virtual environment. Of
course these are generated uh but if you
scroll down a bit you see that there's
an app folder and there's a test folder
and these contain well the app basically
the source code of your project and then
the test of your project. If you look
inside the app folder you see that
there's subfolders here. Now in this
particular example, this is a fast API
app and this is what it looks like in
the main file. So here there's actually
not much going on. Some setup work. We
create the app and I register a router.
This is an API that handles users.
That's all there is to it. And before I
dive further into the code, let's
actually run this app and see what it
does. Now that my app is running, and
I'll talk more about how all of this
works in a minute. I can actually send
requests to this. For example, here I
have a call request to create a user. So
this created a user or what I can also
do is get all the users and that's going
to give me that one user that I just
created. Now like I said, the way that
this is set up and how it's running is
done in a specific way that I'll explain
in a minute. But first, let me go back
to the folder structure. Now this API
has a single route which is the users
route that you saw just before and
that's actually in here. So I have API
v1. You may have multiple versions of
your API if you're uh developing this
incrementally. And here is my user
route. So this is basically the HTTP
layer. And if you look at the actual
code in this route, you see that it's
actually pretty basic. Uh there is the
uh standard routes that you want. You
know, getting the users, creating a
user, getting user by ID, uh doing an
update, doing a delete, basically the
crop operations that you would expect
here. And as you can see, the actual
Sous-titres complets disponibles dans le lecteur vidéo
Entraînez-vous avec des exercices
Générez des exercices de vocabulaire, grammaire et compréhension à partir de cette vidéo
Commentaires (0)
Connectez-vous pour CommenterInscris-toi pour débloquer toutes les fonctionnalités
Suis ta progression, sauvegarde du vocabulaire et entraîne-toi
Mode interactif
Quiz
Rponse correcte :
Quiz
Rponse correcte :
Les quiz apparaissent pendant que tu regardes la vidéo
Astuce mémo
Dans cette vidéo
Apprendre les langues gratuitement