easwee.net // tiny digital playground

hobby guide to ai ep.1 - uv project setup

This is a hobby/beginner guide to AI driven workflows. Some basic terminal and Python knowledge is preferred, but not strictly needed. I will try to provide all of the commands in a sequence so even if just copy/pasted, they should yield results. I am running all of this on Ubuntu with bash, curl and latest Python (currently 3.12) installed, but it should be similar on a Mac, and most likely more painful on Windows. If you run into problems you can hit me up on x.com under @easwee and we can chat, maybe. Let's dive in!

So why even write code, when we already have first AI agents that can code applications for us? It's because I hope some young soul will read this post at some point in the future, get excited about coding, get motivated and insanely good at it and then come fix my future elder-care home robot when it gets jammed. I do care about self-preservation. And also coding is a fun mental exercise, like crosswords. And also just to write down some thoughts.

Project setup #

Python has many package managers, but most of them are trash, so let's just use the best we have at the moment - uv. uv is fast and has a ton of other improvements, that you don't really have to care about just now. Just use uv - trust me bro - and later when you get curious, go read more in their docs.

Open your terminal.

Unless the docs changed - run the uv install command:

curl -LsSf https://astral.sh/uv/install.sh | sh

As you can see curl downloads the uv bash install script and runs it. Wait for it to complete.

uv initializes a Python "project" folder and all your files will be contained within it. Let's initialize one, so we have a base from where to start. I'm gonna call it ai-hobby-lab, but you can call it whatever you like.

uv init ai-hobby-lab

Move into your new project:

cd ai-hobby-lab

And list the contents of this folder including hidden stuff:

ls -la

You should see something like this:

drwxrwxr-x 7 easwee easwee 4096 jan 28 19:19 .git
-rw-rw-r-- 1 easwee easwee  109 jan 28 19:19 .gitignore
-rw-rw-r-- 1 easwee easwee  100 jan 28 19:19 hello.py
-rw-rw-r-- 1 easwee easwee  168 jan 28 19:19 pyproject.toml
-rw-rw-r-- 1 easwee easwee    5 jan 28 19:19 .python-version
-rw-rw-r-- 1 easwee easwee    0 jan 28 19:19 README.md

uv creates your project base files - hello.py is the entry file and the file we will execute once our code is written. But i don't like the name - let's rename it to main.py:

mv hello.py main.py

Let's test if it works:

python main.py

You should see something like this:

Hello from ai-hobbylab!

Virtual environment #

We don't want to pollute our computer with random Python libraries, because sooner or later we will start running in conflicting versions across projects. We will install libraries/packages into a Python virtual environment. uv can create one for us:

uv venv

This creates a .venv folder inside of your project - typical python development stuff - encapsulating your project. Now you need to activate the virtual environment in your terminal, so all the stuff we will do later will run within this virtual environment:

source .venv/bin/activate

Note: You need to activate every time you reopen your terminal.

Note 2: Depending on which terminal shell you use, an active venv could be somehow visually indicated. Also there are ways to have a venv activate automatically each time you open the project folder in terminal - look it up if you want.

Installing required dependencies #

My goal for next episodes is to write a few different nicely commented Python workflow scripts, that you can just copy/paste and run on your machine (and also modify if you wish to be an adventurer).

I obviously don't want to write everything from scratch, so let's install 2 popular battle-tested libraries that will simplify my life a bit.

  1. yt-dlp - a feature-rich command-line audio/video downloader with support for thousands of sites (their description couldn't be more accurate). At some point we will download audio and video from Youtube, but yt-dlp also has adapters for many other popular media websites, if you ever wish to download from elsewhere. It's the best lib in this field.

Install it using uv:

uv add yt-dlp

Note: if you do read the docs, they always say pip install <something>, but we use uv package manager instead of old boy pip, so just replace pip install with uv add when you encounter this.

  1. openai python API - the gipity guys offer a Python library that allows you to call their API if you have an OPENAI_API_KEY, but the good part about this library is that many other companies copy their API structure, so with a tiny change config change, it will work with popular AI APIs too. You will see later.

Install it using uv:

uv add openai

From here on - I don't know about you - but I prefer to write code in a nice code editor. I use VS Code, because it's free and everybody uses it (and because it doesn't cause brain damage like Vim). Always use what most people use, unless you found your reason why something else works for you - but don't be that guy who goes "I did everything as in instructions, but I write code on a typewriter...".

Assuming you have VS Code installed and you are in your project folder inside of terminal, type:

code .

and it will open this project in VS code.

Note: VS Code has a simple integrated terminal - if you have your project opened, you can activate your .venv there and run all scripts within it and you don't need to keep switching out.

This is enough for today. We will do AI things in the next one. And maybe learn something new about uv too!