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
Desbloquea herramientas de aprendizaje con IA
Regístrate para acceder a herramientas potentes que te ayudan a aprender más rápido con cada video.
The Best Way to Share Code Between Python Apps
Subtítulos (443 segmentos)
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
Subtítulos completos disponibles en el reproductor
Practica con ejercicios
Genera ejercicios de vocabulario, gramática y comprensión de este video
Comentarios (0)
Inicia Sesión para ComentarRegístrate para desbloquear todas las funciones
Sigue tu progreso, guarda vocabulario y practica con ejercicios
Modo interactivo
Cuestionario
Respuesta correcta:
Vídeos relacionados
Top 3 Google Play Google I/O 2025 announcements
#WeArePlay: Silver and Bill, Amanotes - Vietnam
Neil deGrasse Tyson Explains The End Of 'Interstellar'
DIGITAL LEVEL REVERSE ENGINEERING amazing sensor...
Tune in on October 30 for our next episode of The Android Show
Late Night with Seth Meyers
Cuestionario
Respuesta correcta:
Los quizzes aparecen mientras ves el video
Truco para recordar
De este video
Aprende idiomas gratis