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.

Explication de scne Chasseur de phrases Rvision par flashcards Pratique de répétition Répondre
S'inscrire gratuitement
Anglais 21:16 Science & Tech

Anatomy of a Scalable Python Project (FastAPI)

Late Night with Seth Meyers · 104,034 vues · Ajouté il y a 1 mois

Sous-titres (534 segments)

00:00

Today I'm going to show you the anatomy

00:02

of a scalable Python project. Here you

00:05

see what my project looks like. This is

00:07

basically the setup that I use for all

00:09

my production projects. So I'm going to

00:12

talk about folder structure, config,

00:15

logging, testing, and tooling that

00:17

together forms a project that's easy to

00:20

work with and that can scale to more

00:22

complexity later on. Now, before we

00:24

start, if you want to learn how to

00:26

design software from scratch, grab my

00:28

free design guide at iron.co/design

00:31

guide. This contains a seven steps that

00:33

I use when I design new software. The

00:36

link is in the video description. Now,

00:38

when I talk about scalable, what do I

00:39

actually mean? Well, first, it should

00:42

scale with size. Basically, your code

00:44

base is going to grow over time,

00:46

assuming you're spending some time

00:48

developing new features. And as your

00:50

code base grows, you don't want to have

00:52

to do a ton of refactoring work. It

00:55

should basically be ready for scale.

00:57

Another way of think about scalability

00:59

is think about how it scales with your

01:01

team. So if you have multiple developers

01:04

that are involved in a project, you want

01:06

to make sure that the boundaries are

01:07

clear, that there are predictable places

01:09

in the code where you're going to add or

01:11

work on features. Then there's also

01:14

scalability with respect to

01:16

environments. So you want to make sure

01:18

that things like config is centralized.

01:21

Uh switching between different

01:23

environments like development, staging,

01:25

production should be uh boring in a good

01:28

way. And finally, there's also scaling

01:30

with speed. So if you have tests, they

01:32

should run fast. Uh having a local

01:35

environment should be really easy to set

01:37

up. Uh Docker works when you need it.

01:39

That kind of thing. Over the years, I've

01:41

worked on many different projects, not

01:44

just Python, but also uh TypeScript,

01:46

Java, C++, anything. And of course,

01:49

depending on the language, things are

01:50

going to be slightly different. So, what

01:52

I'll show you today is something that

01:53

works for me really well in Python. I'd

01:56

like to start with the folder structure,

01:58

which should be balanced. You want

02:00

things to be organized, but you don't

02:02

want things to be so structured in

02:04

folders that they're impossible to find.

02:06

So here's how I have set this up in this

02:09

particular project. Now there are some

02:12

folders here at the top uh which is some

02:14

caching and the virtual environment. Of

02:16

course these are generated uh but if you

02:19

scroll down a bit you see that there's

02:20

an app folder and there's a test folder

02:23

and these contain well the app basically

02:26

the source code of your project and then

02:29

the test of your project. If you look

02:31

inside the app folder you see that

02:33

there's subfolders here. Now in this

02:36

particular example, this is a fast API

02:38

app and this is what it looks like in

02:40

the main file. So here there's actually

02:42

not much going on. Some setup work. We

02:44

create the app and I register a router.

02:47

This is an API that handles users.

02:50

That's all there is to it. And before I

02:52

dive further into the code, let's

02:54

actually run this app and see what it

02:56

does. Now that my app is running, and

02:58

I'll talk more about how all of this

03:00

works in a minute. I can actually send

03:02

requests to this. For example, here I

03:05

have a call request to create a user. So

03:07

this created a user or what I can also

03:10

do is get all the users and that's going

03:12

to give me that one user that I just

03:15

created. Now like I said, the way that

03:17

this is set up and how it's running is

03:18

done in a specific way that I'll explain

03:20

in a minute. But first, let me go back

03:22

to the folder structure. Now this API

03:25

has a single route which is the users

03:28

route that you saw just before and

03:31

that's actually in here. So I have API

03:33

v1. You may have multiple versions of

03:36

your API if you're uh developing this

03:38

incrementally. And here is my user

03:42

route. So this is basically the HTTP

03:44

layer. And if you look at the actual

03:46

code in this route, you see that it's

03:48

actually pretty basic. Uh there is the

03:51

uh standard routes that you want. You

03:53

know, getting the users, creating a

03:55

user, getting user by ID, uh doing an

03:58

update, doing a delete, basically the

03:59

crop operations that you would expect

04:01

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

Vocabulaire et grammaire Quiz de compréhension Examen IELTS Pratique de l'crit
S'inscrire pour pratiquer
Pas encore de commentaires. Soyez le premier à partager vos idées !

Inscris-toi pour débloquer toutes les fonctionnalités

Suis ta progression, sauvegarde du vocabulaire et entraîne-toi

Apprendre les langues gratuitement