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 18:28 Science & Tech

The Best Way to Share Code Between Python Apps

Late Night with Seth Meyers · 41,689 vues · Ajouté il y a 1 mois

Sous-titres (443 segments)

00:00

If you're managing multiple Python apps

00:02

in one project, one repository, that can

00:05

be quite messy. You'll have multiple

00:07

virtual environments, log files,

00:09

different versions of dependencies, and

00:11

so on. But with UV workspaces, you can

00:15

actually manage multiple apps with

00:17

shared code, shared dependencies pretty

00:20

cleanly. So today, I'll show you how

00:22

that works. And I'm going to do that by

00:24

building a CLI tool, a fast API app that

00:27

both fetch headlines from hacker news

00:29

and summarize them using an LLM. And

00:32

I'll set it all up using UV workspaces

00:34

to keep everything fast and dry, which

00:38

by the way, it's not at all in the

00:41

Netherlands at the moment. It's raining

00:43

quite a lot. So at least my coat is

00:45

going to be dry. That's something that I

00:47

have to hang on to. Now, here's the

00:49

example that I'm going to work with

00:51

today. I have this command line

00:53

interface. You see there is a bit of a

00:55

mess here with the imports. Uh I'll

00:58

clean that up in a minute. But actually

01:00

the code here is uh pretty basic. I'm

01:03

using some uh libraries like hpx and

01:06

beautiful soup to get some news from uh

01:08

hacker news. So there's a function here

01:10

that fetches headlines from that site

01:13

and then it parses the text using

01:16

beautiful soup and it tries to get some

01:17

titles from it. Then what it does is it

01:21

creates a command line interface using

01:24

typer which by the way is also an

01:25

awesome package and I define a command

01:28

headlines that gets these headlines and

01:30

then simply prints them nicely using

01:33

rich which is another nice package. Lots

01:36

of nice packages here. Now the setup for

01:38

this code is also pretty simple. I have

01:39

a pi project file that just has a couple

01:42

of dependencies.

01:44

I can install these dependencies like so

01:47

and then I can run my main file. Now

01:51

there's no requires Python. There's a

01:53

reason for that. I'll talk about that in

01:54

a minute. But basically not get some

01:56

headlines from hacker news like mpm

01:59

malware. Yeah, don't use that. Well, if

02:02

you're doing web development, you

02:03

probably have no choice uh hosting

02:05

website and so on and so on. So this

02:07

seems to work as expected. Now, the

02:10

problem comes when you're not just

02:12

dealing with one package, but if you're

02:15

trying to add more things to this, let's

02:17

say you also want to build an API that

02:20

actually retrieves this for you. And

02:22

since this is so closely related to the

02:24

CLI, you're going to want to put it in

02:26

the same repository. So then you would

02:28

create another folder which would have

02:30

your fast API app. And magically, I have

02:34

actually already done that. So as you

02:36

can see I have an API folder here which

02:38

has a main file uh that's a fast API app

02:43

uses uicorn to run the server and it has

02:46

a headlines endpoint

02:49

which well fetches the headlines and

02:51

then returns that as JSON data. Now the

02:54

problem here is that we had to copy a

02:56

lot of code. Uh this fetch headlines

02:58

function had to copy that over. uh I had

03:01

to also copy the dependencies because

03:03

now this API also needs beautiful soup

03:06

and httpx and that's obviously not

03:09

ideal. Now you could try to turn this

03:11

into a package and publish it on pipi or

03:13

something and then use it here but

03:14

that's also kind of annoying. You want

03:16

to be able to just do that locally,

03:18

right? Uh you could uh create like one

03:21

big Python package and then have uh

03:23

undumber in it files everywhere which is

03:26

maybe also not ideal. And this is a

03:28

place where the UV workspace comes in

03:30

very handy. The first thing you can do

03:32

with this is that you can define shared

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