1/5
## Adding Python packages/libraries with UV The UV tool helps us manage Python packages and dependencies across different projects and versions. We'll use the **Titanoboa** package in this lesson to showcase how UV can be used to manage dependencies. **Titano Boa** is a package that allows us to evaluate code written in Python. First, let's create a simple Python script that will utilize **Titanoboa**. ```python import boa import sys print(boa.eval('"empty(uint256())"')) print("Hello!") ``` If we try to run this script without having **Titano Boa** installed, we'll encounter an error message as **Titanoboa** is not available. **Let's install Titano Boa globally using pip** ```bash python3.11 -m pip install titano Boa ``` This will install **Titano Boa** for the global Python 3.11 environment. Now we can run our script and we'll see the output: ```bash python3.11 basic_python.py ``` We get the correct output because **Titano Boa** was installed globally in our Python 3.11 environment. **UV's strength lies in its ability to manage dependencies for specific project environments. Let's demonstrate this.** **We'll add Titano Boa to our project environment using UV.** **Add a dependency with UV** ```bash uv add titano Boa ``` This will create a new folder called `venv` in our project directory and automatically add **Titano Boa** to the project environment. **UV will also generate a `uv.lock` file.** This file keeps track of all dependencies for our project. **Run our script with UV** ```bash uv run python basic_python.py ``` This will run our script using the Python version and packages specified in our project environment. We can now switch to different Python versions or add different packages to our project, and UV will ensure that the correct versions are used when running our script. **Using pyproject.toml** ```toml [project] name = "Python-in-updraft-cu" version = "0.1.1.0" description = "Add your description here" readme = "README.md" requires-python = ">=3.11" dependencies = [ "titano Boa>=0.2.4", ] ``` The `pyproject.toml` file acts as a configuration file for our project, defining dependencies and other project-related details. When we used `uv add titano Boa`, UV updated this file to include **Titano Boa** in our dependency section. UV's flexibility allows us to easily switch between different Python versions and environments without the hassle of managing global packages or manually installing dependencies for each project.
A powerful tutorial on adding Python packages and libraries with UV - The lesson covers the basics of using UV to install and manage packages, including adding a package to a virtual environment, specifying package versions, and understanding how UV handles dependencies across different projects and Python versions.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on January 14, 2025
Duration: 2h 20min
Duration: 1h 51min
Duration: 58min
Duration: 2h 23min
Duration: 53min
Duration: 2h 24min
Duration: 28min
Duration: 1h 54min
Duration: 11min
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on January 14, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar