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.
The Best Way to Share Code Between Python Apps
Sous-titres (443 segments)
If you're managing multiple Python apps
in one project, one repository, that can
be quite messy. You'll have multiple
virtual environments, log files,
different versions of dependencies, and
so on. But with UV workspaces, you can
actually manage multiple apps with
shared code, shared dependencies pretty
cleanly. So today, I'll show you how
that works. And I'm going to do that by
building a CLI tool, a fast API app that
both fetch headlines from hacker news
and summarize them using an LLM. And
I'll set it all up using UV workspaces
to keep everything fast and dry, which
by the way, it's not at all in the
Netherlands at the moment. It's raining
quite a lot. So at least my coat is
going to be dry. That's something that I
have to hang on to. Now, here's the
example that I'm going to work with
today. I have this command line
interface. You see there is a bit of a
mess here with the imports. Uh I'll
clean that up in a minute. But actually
the code here is uh pretty basic. I'm
using some uh libraries like hpx and
beautiful soup to get some news from uh
hacker news. So there's a function here
that fetches headlines from that site
and then it parses the text using
beautiful soup and it tries to get some
titles from it. Then what it does is it
creates a command line interface using
typer which by the way is also an
awesome package and I define a command
headlines that gets these headlines and
then simply prints them nicely using
rich which is another nice package. Lots
of nice packages here. Now the setup for
this code is also pretty simple. I have
a pi project file that just has a couple
of dependencies.
I can install these dependencies like so
and then I can run my main file. Now
there's no requires Python. There's a
reason for that. I'll talk about that in
a minute. But basically not get some
headlines from hacker news like mpm
malware. Yeah, don't use that. Well, if
you're doing web development, you
probably have no choice uh hosting
website and so on and so on. So this
seems to work as expected. Now, the
problem comes when you're not just
dealing with one package, but if you're
trying to add more things to this, let's
say you also want to build an API that
actually retrieves this for you. And
since this is so closely related to the
CLI, you're going to want to put it in
the same repository. So then you would
create another folder which would have
your fast API app. And magically, I have
actually already done that. So as you
can see I have an API folder here which
has a main file uh that's a fast API app
uses uicorn to run the server and it has
a headlines endpoint
which well fetches the headlines and
then returns that as JSON data. Now the
problem here is that we had to copy a
lot of code. Uh this fetch headlines
function had to copy that over. uh I had
to also copy the dependencies because
now this API also needs beautiful soup
and httpx and that's obviously not
ideal. Now you could try to turn this
into a package and publish it on pipi or
something and then use it here but
that's also kind of annoying. You want
to be able to just do that locally,
right? Uh you could uh create like one
big Python package and then have uh
undumber in it files everywhere which is
maybe also not ideal. And this is a
place where the UV workspace comes in
very handy. The first thing you can do
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
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 :
Vidéos liées
Late Night with Seth Meyers
Quiz
Rponse correcte :
Les quiz apparaissent pendant que tu regardes la vidéo
Astuce mémo
Dans cette vidéo
Apprendre les langues gratuitement