Movatterモバイル変換


[0]ホーム

URL:


— FREE Email Series —

🐍 Python Tricks 💌

Python Tricks Dictionary Merge

🔒 No spam. Unsubscribe any time.

Browse TopicsGuided Learning Paths
Basics Intermediate Advanced
aialgorithmsapibest-practicescareercommunitydatabasesdata-sciencedata-structuresdata-vizdevopsdjangodockereditorsflaskfront-endgamedevguimachine-learningnewsnumpyprojectspythonstdlibtestingtoolsweb-devweb-scraping

Table of Contents

Recommended Course

Managing Python Projects With uv: An All-in-One Solution

Python Project Management With uv

48m · 10 lessons

Managing Python Projects With uv: An All-in-One Solution

Managing Python Projects With uv: An All-in-One Solution

byLeodanis Pozo RamosPublication date Apr 28, 2025Reading time estimate 28mintermediatetools

Table of Contents

Remove ads

Recommended Course

Python Project Management With uv(48m)

The uv tool is a high-speed package and project manager for Python. It’s written in Rust and designed to streamline your workflow. It offers fast dependency installation and integrates various functionalities into a single tool.

With uv, you can install and manage multiple Python versions, create virtual environments, efficiently handle project dependencies, reproduce working environments, and even build and publish a project. These capabilities make uv an all-in-one tool for Python project management.

By the end of this tutorial, you’ll understand that:

  • uv is a Python package and project manager that integrates multiple functionalities into one tool, offering a comprehensive solution for managing Python projects.
  • uv is used for fast dependency installation, virtual environment management, Python version management, and project initialization, enhancing productivity and efficiency.
  • uv can build and publish Python packages to package repositories like PyPI, supporting a streamlined process from development to distribution.
  • uv automatically handles virtual environments, creating and managing them as needed to ensure clean and isolated project dependencies.

To dive deeper into managing your Python projects efficiently with uv, you should have a basic understanding of using Python virtual environments, setting uppyproject.toml files for projects, and building distributable packages for a project.

Get Your Code:Click here to download the free sample code you’ll use to learn about managing Python projects with uv.

Take the Quiz: Test your knowledge with our interactive “Managing Python Projects With uv: An All-in-One Solution” quiz. You’ll receive a score upon completion to help you track your learning progress:


Managing Python Projects With uv: An All-in-One Solution

Interactive Quiz

Managing Python Projects With uv: An All-in-One Solution

In this quiz, you'll test your understanding of the uv tool, a high-speed package and project manager for Python.

Getting to Know uv for Python

Recently, a few exciting tools built with theRust programming language have appeared in the Python tooling ecosystem.Ruff—a linter and code formatter for Python—is a well-known and popular example of one of these tools.

In this tutorial, you’ll explore another cool tool made with Rust for Python. You’ll get to knowuv, an extremely fast Pythonpackage and project manager.

The main idea behind these tools is to accelerate your Python workflow by speeding up your project management actions. For example, Ruff is 10 to 100 times faster than linters likeFlake8 and code formatters likeBlack. Similarly, for package installation, uv is10 to 100 times faster thanpip.

Additionally, uv integrates into one tool most of the functionality provided by tools likepip,pip-tools,pipx,poetry,pyenv,twine,virtualenv, and more. Therefore, uv is an all-in-one solution.

Here’s a quick list of key uv features for managing your Python projects:

  • Fast dependency installation: Installs dependencies really fast, which is especially useful for large dependency trees.
  • Virtual environment management: Automatically creates and managesvirtual environments.
  • Python version management: Allows the installation and management of multiple Python versions.
  • Project initialization: Scaffolds a full Python project, including the root directory,Git repository, virtual environment,pyproject.toml,README, and more.
  • Dependency management: Installs, updates, removes, and locks direct andtransitive dependencies, which allows for environment reproducibility.
  • Package builds and publication management: Allows you to build and publish packages to package repositories like thePython Package Index (PyPI).
  • Developer tooling support: Installs and lets you run development tools, such aspytest, Black, and Ruff.

Apart from these features, uv is a standalone binary that allows for a smooth installation and quick upgrades. You don’t need to have Python installed on your system to install uv.

So, with this quick summary of uv and its main features, you’re ready to install this tool on your system. That’s what you’ll do in the following section. Additionally, you’ll learn how to update your uv installation.

Installing uv to Manage Python Projects

The first step in using any tool is to install it on your operating system. To install uv, you have several options. The quickest one would be to use the standalone installer. Another friendly option is to install uv fromPyPI using other tools likepipx orpip.

In the officialuv installation guide, you’ll find several other installation options. For example, you can use tools likeHomebrew andCargo, depending on your current platform and operating system. However, in this tutorial, you’ll only explore the standalone installer and the PyPI options.

Using the Standalone Installer

The uv project provides a standalone installer that you can use to download and install the tool in your system. Below are the relevant commands for the three main operating systems:

Windows PowerShell
PS>powershell-ExecutionPolicyByPass-c"irm https://astral.sh/uv/install.ps1 | iex"
Shell
$curl-LsSfhttps://astral.sh/uv/install.sh|sh

If you don’t havecurl installed on your system, then you can usewget as shown below:

Shell
$wget-qO-https://astral.sh/uv/install.sh|sh

These commands will download and install the latest binary of uv in your system. If you’d like to install a specific version of the tool instead of the latest, then you can add the version number to the download URL right after theuv/ part:

https://astral.sh/uv/0.6.12/install.ps1
https://astral.sh/uv/0.6.12/install.sh

With this addition to the download URL, you request the installation of uv version0.6.12. Once you’ve downloaded and installed uv with the appropriate command, you can verify the installation by running the following command:

Shell
$uv--versionuv 0.6.12 (e4e03833f 2025-04-02)

Now you’re all set up with uv. In this case, you’re using version0.6.12. Of course, your specific version may differ slightly depending on when you read this tutorial.

You can run theuv --help command at any time to display the help page, which provides detailed information about each command and option the tool offers. Go ahead and give it a try!

Installing From PyPI

You can also install uv from thePython Package Index (PyPI) usingpipx. As with the standalone installer, the uvcommand-line-interface (CLI) will be available globally on your system.

To install uv usingpipx, run the following command:

Shell
$pipxinstalluv

Note that for this command to work, you needpipx to be available in your environment. This involves an extra step. If you don’t want to install an additional app, then you can usepip, which is typically shipped by default with most Python distributions.

However, to have system-wide access to uv, you’ll have to install it in your Python system installation. This isn’t recommended because it could clutter your system with packages that you may not use.

Upgrading to the Latest uv Version

As you know, time flies. The uv project is currently under active development, which means that new versions are released regularly.

If you’ve installed uv using thestandalone installer and would like to be up to date with the latest version, then you can run the following command:

Shell
$uvselfupdateinfo: Checking for updates...success: Upgraded uv from v0.6.10 to v0.6.12!⮑ https://github.com/astral-sh/uv/releases/tag/0.6.12

Theuv self update command checks whether a new version is available. If that’s the case, the command downloads the new package and installs it for you.

If you’ve installed uv withpipx and want to upgrade it, then you can run the command below:

Shell
$pipxupgradeuv

This command allows you to upgrade your uv installation to the latest version if you usedpipx.

Handling Python Projects With uv

Now comes the fun part—the part where you create and manage a Python project with uv. In this section, you’ll explore the uv features and commands that allow you to do this quickly and efficiently.

For this section and the rest of the tutorial, you’ll use a sample CLI application that retrieves cat information from theCat API.

Click theShow/Hide toggle below to reveal the app’s code:

Pythonmain.py
importargparseimportsysimportrequestsdefget_breeds_info():response=requests.get("https://api.thecatapi.com/v1/breeds")response.raise_for_status()returnresponse.json()deffind_breed_info(breed_name):json_response=get_breeds_info()forbreedinjson_response:ifbreed["name"]==breed_name:returnbreedreturnNonedefdisplay_breed_profile(breed):print(f"\n{breed['name']:-^30s}")print(f"Origin:{breed['origin']}")print(f"Temperament:{breed['temperament']}")print(f"Life Span:{breed['life_span']} years")print(f"Weight:{breed['weight']['imperial']} lbs")ifbreed.get("wikipedia_url"):print(f"\nLearn more:{breed['wikipedia_url']}")defparse_args():parser=argparse.ArgumentParser(description="Get information about cat breeds")parser.add_argument("breed",help="Name of cat breed (e.g., 'Siamese')",)returnparser.parse_args()defmain():args=parse_args()try:breed=find_breed_info(args.breed)ifnotbreed:print("Breed not found. Try another breed name.")return0display_breed_profile(breed)exceptExceptionase:print(f"Error:{e}")return1return0if__name__=="__main__":sys.exit(main())

Keep this code handy! You’ll use it to spice up your first Python project with uv. Are you ready?

Creating a Python Project

To create and initialize a Python project with uv, navigate to the directory where you want to store the project. Once there, you can run the following command to create and initialize the project:

Shell
$uvinitrpcats

Note that the project name is up to you. In this example, you’ll userpcats to denote that this is a Real Python project for retrieving and displaying information about cats.

The command above creates the following directory structure under therpcats/ folder:

rpcats/│├── .git/│├── .gitignore├── .python-version├── README.md├── main.py└── pyproject.toml

This is cool! First, you have the.git/ directory, which is the Git repository for your project. The.gitignore file allows you to define the files and folders you want to skip in your version control workflow. By default, uv automatically populates this file with sensible entries for most Python projects, ensuring that unwanted files are excluded from version control.

The.python-version file contains the default Python version for the current project. This file tells uv which Python version to use when creating a dedicated virtual environment for the project. Next, you have an emptyREADME.md file that you can use to provide basic documentation for your project.

Themain.py file is a placeholder Python file that initially contains the following code:

Python
defmain():print("Hello from rpcats!")if__name__=="__main__":main()

In this case, you have amain() function that prints a message to the screen. At the bottom of the file, you have the well-knownif __name__ == "__main__" idiom, which is common practice in executable files like this one.

Finally, you have thepyproject.toml file with the following initial content:

TOML
[project]name="rpcats"version="0.1.0"description="Add your description here"readme="README.md"requires-python=">=3.13"dependencies=[]

This file contains basic configuration key-value pairs under the[project] table. You can update the value of any key to meet your requirements. For example, you can change thedescription to something like the following:

TOML
[project]name="rpcats"version="0.1.0"description="Display cat information for the specified breed."readme="README.md"requires-python=">=3.13"dependencies=[]

Now, your project has a concrete description. You could also change the project’s version, the required Python version, and so on.

Note: If you want to start managing an existing project with uv, then navigate to the project directory and run the following command:

Shell
$uvinit

This command will create the uv project structure for you. It won’t overwrite themain.py file if you have one, but it’ll create the file if it’s missing. It neither modifies your Git repository nor yourREADME.md file.

However, this command won’t work if you already have apyproject.toml file in place. If that’s the case, then you can move the file to another location and run theuv init command. Finally, you can update the new file with any relevant configuration from your oldpyproject.toml.

That’s it! You’ve created your first project with uv. Now you can run the project’s entry-point script,main.py, to check that everything’s working correctly.

Running the Project’s Entry-Point Script

Once you’ve created the project, you can use uv to run the entry-point script, which is themain.py file by default. To run the script, go ahead and execute the following command:

Shell
$uvrunmain.pyUsing CPython 3.13.2Creating virtual environment at: .venvHello from rpcats!

The first time you run this command, it’ll display the Python version you’re currently using for the project. It’ll also inform you that uv has created a dedicated Python virtual environment for the project. The final output line shows the message that results from calling themain() function defined inmain.py.

Note: You can change the entry-point script’s name and location at any time. Naming itmain.py isn’t mandatory.

If you check the content of your project’s root directory again, then you’ll find a.venv folder containing the dedicated virtual environment. You’ll also find a new file calleduv.lock, which is a cross-platformlockfile that contains information about your project’s dependencies. This file ensures that other developers can quickly and exactly reproduce your working environment. This enhances team collaboration and code contributions.

Unlikepyproject.toml, which usually specifies the direct dependencies of your project, theuv.lock file contains the exact versions of any dependency installed in the project environment.

Theuv.lock file uses theTOML format. You should add this file to version control. However, you shouldn’t edit this file manually. Instead, you can let uv take care of it. You’ll learn more about this file in a moment.

Using uv for Dependency Management

When it comes to managing your project’s dependencies, uv makes your life easier with a clean workflow. This workflow allows you to lock your project’s dependencies so that other developers can reproduce your environment exactly and contribute to your code without much setup effort.

In the following sections, you’ll learn the basic uv commands that you should use to install, update, and remove external packages and libraries. You’ll also learn how these commands create and update the corresponding configuration files to ensure reproducibility.

Adding and Installing Dependencies

Now, go back to the beginning of theHandling Python Projects With uv section, expand the collapsible block, and copy the code for the sample CLI app. Paste the code into themain.py file in your project’s root folder.

Once you have the code in place, you might be tempted to run the app with a command like the following:

Shell
$uvrunmain.pyPersianTraceback (most recent call last):    ...ModuleNotFoundError: No module named 'requests'

The app fails with aModuleNotFoundError exception. Why? Because you haven’t installed the required dependencies in your working environment.

In your cat app example, you need theRequests library, which is a popular library for making HTTP requests in Python. You use this library to retrieve cat information from the Cat API.

Go ahead and run the following command to make uv addrequests:

Shell
$uvaddrequests

This command lets you add the Requests library to your project’s dependencies. It also installs the library in your project’s virtual environment. Once it finishes running, go ahead and check the content of yourpyproject.toml file:

TOML
[project]name="rpcats"version="0.1.0"description="Display cat information for the specified breed."readme="README.md"requires-python=">=3.13"dependencies=["requests>=2.32.3",]

Notice howuv add automatically updates your list of dependencies by addingrequests to thepyproject.toml file. In this case, the installed version should be greater or equal to2.32.3.

Note: If you’re working on an existing project and want to migrate from arequirements.txt file to using uv, then you can run the following command:

Shell
$uvadd-rrequirements.txt

This command imports the dependencies declared in your existingrequirements.txt file into the uv infrastructure.

Internally,uv add also updates theuv.lock file with version information for the following:

  • Direct dependencies: Packages that your project depends on directly. For example, your cat app depends onrequests.
  • Transitive dependencies: Packages that support your project’s direct dependencies. For example, the Requests library depends onurllib3, and you get it installed as a transitive dependency.

You don’t have to worry about theuv.lock content and shouldn’t edit it yourself. Instead, let uv be in charge of it. However, you must version-control it.

As you can conclude,uv add does the dependency management work for you. It installs the dependencies, edits thepyproject.toml file if necessary, and keeps theuv.lock file up-to-date. This ensures that other developers can reproduce your working environment.

Note: Even though uv has analternative interface that mimicspip, you shouldn’t use it to install dependencies because these commands won’t update theuv.lock file orpyproject.toml automatically likeuv add does.

Would you like to give your cat app another try? Go ahead and run it:

Shell
$uvrunmain.pyPersian-----------Persian------------Origin: Iran (Persia)Temperament: Affectionate, Loyal, Sedate, QuietLife Span: 14 - 15 yearsWeight: 9 - 14 lbsLearn more: https://en.wikipedia.org/wiki/Persian_(cat)

Now, your cat app is working correctly. It makes API requests, processes the responses, and displays information for the target breed of cat.

Upgrading and Removing Dependencies

You can also use uv to update and remove dependencies. For example, say that some time has passed since you released the latest version of yourrpcats app, and you’d like to continue the development by adding new features. However, you realize a new version is available for the Requests library.

In this situation, you can use the following command to upgraderequests:

Shell
$uvadd--upgraderequests

This command upgradesrequests and updates its version information in theuv.lock file. This action allows you to work with the library’s latest version and ensures that other developers can do the same.

If you decide at any point that your project doesn’t need a dependency anymore, then you can remove it with the following command:

Shell
$uvremove<package_name>

For example, if you’d like yourrpcats app to check for multiple cats at once, you might want to use a library likeaiohttp, which is capable of makingasync HTTP requests. In that case, you can removerequests and addaiohttp.

It’s important to note thatuv remove also removes transitive dependencies and updates thepyproject.toml anduv.lock files accordingly.

Managing Development Dependencies

In most development environments, you’ll have dependencies that aren’t required for running the code but are vital for developing it. For example, testing libraries likepytest, code formatters like Ruff, and static type checkers likemypy might be some of these development dependencies.

You can use uv to manage these types of dependencies. This time, you’ll use theuv add command with the--dev flag. For example, say that you want to write tests for the cats app. To do this, you want to usepytest. Because your project doesn’t need this library to run, you can install it as a development dependency:

Shell
$uvadd--devpytest

This command will installpytest in your project’s virtual environment and add the library as a development dependency to yourpyproject.toml anduv.lock files.

If you check the content ofpyproject.toml after running the command above, then you’ll find the following:

TOMLpyproject.toml
[project]name="rpcats"version="0.1.0"description="Display cat information for the specified breed."readme="README.md"requires-python=">=3.13"dependencies=["requests>=2.32.3",][dependency-groups]dev=["pytest>=8.3.5",]

The highlighted lines show how uv automatically updated the file to includepytest in your list of development dependencies. You can also check the content ofuv.lock if you want to confirm thatpytest is there as well.

Now you can write the tests for your projects!

Locking and Syncing the Environment

As you’ve already learned, uv uses theuv.lock file to lock a project’s dependencies.Locking consists of capturing your project’s specific dependencies in the lockfile. This process makes it possible to reproduce your working environment in all possible configurations, including the Python version and distribution, the operating system, and the architecture.

As a counterpart,syncing is the process of installing the required packages from the lockfile into the project’s development environment.

Both locking and syncing processes are automatically handled by uv. For example, when you executeuv run, the project is locked and synced before the command is invoked. This behavior ensures that your project’s environment is always up to date.

Now, imagine that you’ve pulled the cat app from a GitHub repository and would like to try it. In this scenario, you’ll only have the source code and the uv configuration files. You won’t have a proper Python virtual environment with the required dependencies to run the app.

To reproduce this situation, you can go ahead and remove the.venv/ folder from the project’s root directory. Then, let uv do the hard work for you:

Shell
$uvrunmain.py"Scottish Fold"Using CPython 3.13.2Creating virtual environment at: .venvInstalled 9 packages in 53ms--------Scottish Fold---------Origin: United KingdomTemperament: Affectionate, Intelligent, Loyal, Playful, Social, Sweet, LovingLife Span: 11 - 14 yearsWeight: 5 - 11 lbsLearn more: https://en.wikipedia.org/wiki/Scottish_Fold

As you can see, before trying to execute the app, uv creates a dedicated virtual environment at the.venv/ directory. Then, it installs the dependencies and finally runs the app.

To make sure that uv has reproduced the environment correctly, you can run the following command:

Shell
$uvpiplistPackage            Version------------------ ---------certifi            2025.1.31charset-normalizer 3.4.1idna               3.10iniconfig          2.1.0packaging          24.2pluggy             1.5.0pytest             8.3.5requests           2.32.3urllib3            2.3.0

This is the list of packages installed in the project’s virtual environment and their specific versions. You can compare this list with the content of theuv.lock file. The packages and versions will coincide, which ensures the exact reproduction of the original development environment.

Note: In the example above, you used thepip interface of uv. In this case, that’s perfectly valid because you aren’t changing the environment but retrieving information from it.

Finally, you can explicitly lock and sync your project with the following commands:

Shell
$uvlock$uvsync

These commands are helpful if you encounter issues with running the project and want to ensure that you’re using the correct version of each dependency.

Building and Publishing Packages

Now, say that your cat project is polished and ready to release a new version. You can also use uv to build and publish the project to a package repository like PyPI. First, you need to set some final options in theproject.toml file. Next, you can build a distribution. You’ll learn about both topics in the following sections.

Configuring the Project

Your cat app has a command-line interface (CLI), so you need to explicitly set the project’s entry-point script so that the build system can properly set up the executable file for the app. Go to thepyproject.toml file and add the following:

TOMLpyproject.toml
[project]name="rpcats"version="0.1.0"description="Display cat information for the specified breed."readme="README.md"requires-python=">=3.13"dependencies=["requests>=2.32.3",][dependency-groups]dev=["pytest>=8.3.5",][project.scripts]rpcats="main:main"

With these two additional lines, you ensure that when someone installs your app, they can run therpcats command from their terminal to execute the code from themain() function, which is stored in themain.py file.

Next, you need to define a build system. In this tutorial, you’ll useSetuptools as the build system. Go ahead and add the following lines to the end of yourpyproject.toml file:

TOMLpyproject.toml
[project]name="rpcats"version="0.1.0"description="Display cat information for the specified breed."readme="README.md"requires-python=">=3.13"dependencies=["requests>=2.32.3",][dependency-groups]dev=["pytest>=8.3.5",][project.scripts]rpcats="main:main"[build-system]requires=["setuptools>=78.1.0","wheel>=0.45.1"]build-backend="setuptools.build_meta"

The first highlighted line specifies that the build system will requiresetuptools andwheel. The second highlighted line defines the build backend. With these two additions to theproject.toml file, you’re ready to build a distribution for your app.

Building a Distribution

You can use theuv build command to build source and binary distributions for your Python project. By default,uv build will build the project and place the distributions in adist/ subdirectory under the project’s root:

Shell
$uvbuildBuilding source distribution...running egg_infocreating rpcats.egg-info...Successfully built dist/rpcats-0.1.0.tar.gzSuccessfully built dist/rpcats-0.1.0-py3-none-any.whl

When you type in theuv build command and pressEnter, the building process starts. You’ll see a detailed output on your terminal screen. At the end of the output, you’ll get a message telling you that the package has been successfully built.

You also have the following build options:

  • uv build --sdist
  • uv build --wheel

The first command builds asource distribution only, while the second command builds abinary distribution. Note that usinguv build without any flags will build both the source and binary distributions.

Publishing a Distribution

The final step is to publish the built package to a package repository like PyPI so that your users can download and install it on their systems.

Beforepublishing a package to PyPI, you should make sure that everything works correctly. To this end, you can publish your package to theTestPyPI index, which is a special repository designed for testing purposes. You’ll need to set up anaccount in TestPyPI and generate anAPI token. Once you’ve done that, you can manually edit yourpyproject.toml file as shown below:

TOML
[project]name="rpcats"version="0.1.0"description="Display cat information for the specified breed."readme="README.md"requires-python=">=3.13"dependencies=["requests>=2.32.3",][dependency-groups]dev=["pytest>=8.3.5",][project.scripts]rpcats="main:main"[build-system]requires=["setuptools>=78.1.0","wheel>=0.45.1"]build-backend="setuptools.build_meta"[[tool.uv.index]]name="testpypi"url="https://test.pypi.org/simple/"publish-url="https://test.pypi.org/legacy/"explicit=true

With these additions, you set up a custom index calledtestpypi. You must also change thename key to something unique that doesn’t exist in TestPyPI. Otherwise, you won’t be able to upload the package because the name already exists.

Now, you can useuv publish with the--index option to upload your app to TestPyPI:

Shell
$uvpublish--indextestpypi--tokenyour_token_here

To run this command, you’ll need to add your personal API token for TestPyPI following the--token option. Once you’ve entered all the information, pressEnter to upload the app to TestPyPI. That should be it!

To try the app, you’ll create a new virtual environment in a different directory. So, go ahead and open a terminal window in any other directory on your hard drive. Then, run the following commands:

Shell
$uvvenvUsing CPython 3.13.2Creating virtual environment at: .venvActivate with: source .venv/bin/activate$uvpipinstall-ihttps://test.pypi.org/simple/rpcats  × No solution found when resolving dependencies:  ╰─▶ Because only requests==2.5.4.1 is available and rpcats==0.1.0 depends on      requests>=2.32.3, we can conclude that rpcats==0.1.0 cannot be used.      And because only rpcats==0.1.0 is available and you require rpcats, we      can conclude that your requirements are unsatisfiable.

With theuv venv command, you create a fresh virtual environment in your working directory under the.venv folder.

Note: In the example above, you fall back on using thepip interface for uv because you’re not managing a project. Instead, you’re just creating a virtual environment and installing a package for testing purposes. While thepip interface is available for use cases like this, it’s not intended for project management.

Next, you try to installrpcats from TestPyPI using the-i option ofuv pip. The installation fails because uv is trying to install arequests version greater than or equal to2.32.3, as your dependencies state. However, the latestrequests version in TestPyPI is2.5.4.1, which doesn’t fulfill your needs.

To work around this issue, you can installrequests from PyPI and then installrpcats as before:

Shell
$uvpipinstallrequests$uvpipinstall-ihttps://test.pypi.org/simple/rpcats$uvrunrpcatsPersian-----------Persian------------Origin: Iran (Persia)Temperament: Affectionate, Loyal, Sedate, QuietLife Span: 14 - 15 yearsWeight: 9 - 14 lbsLearn more: https://en.wikipedia.org/wiki/Persian_(cat)

Here, you manually install Requests from PyPI. Next, you installrpcats from TestPyPI with the same command as before. Finally, you runrpcats with theuv run command to make sure it works properly. Note that you’re not runningmain.py, butrpcats as a command instead.

Once you’re sure your project works correctly, you can upload it to PyPI’s main index. Again, you need to have anaccount and an API token.

Note: To keep PyPI unpolluted, you shouldn’t uploadrpcats to the index. Remember that this is just a sample project for learning purposes, not a fully functional app.

Once you have the account and the token at hand, run the following command to publish your package:

Shell
$uvpublish--tokenyour_token_here

This command uses PyPI as its default package index. As with TestPyPI, you need to enter yourAPI token. Once the command is done, your app will be available in PyPI, and you’ll be able to install it like any other Python package.

Conclusion

You’ve learned all about uv, a fast, Rust-based package and project manager for Python. You’ve explored its features for creating projects, setting up virtual environments, managing dependencies, building and publishing projects, and more.

Understanding how to manage Python projects effectively is crucial for any Python developer. With uv, you have an all-in-one solution that speeds up your workflow and simplifies project management, making it an invaluable tool for both beginners and experienced developers.

In this tutorial, you’ve learned how to:

  • Install uv on your operating system
  • Create and manage Pythonprojects with uv
  • Handledependencies efficiently with uv commands
  • Build and publish Python packages to PyPI or private indexes
  • Set updeveloper tools within uv for a streamlined workflow

With these skills, you’ll manage your Python projects more efficiently, ensuring smooth development and deployment processes. You can use uv to handle project dependencies, automate environment setup, and improve collaboration across your development team.

Get Your Code:Click here to download the free sample code you’ll use to learn about managing Python projects with uv.

Frequently Asked Questions

Now that you have some experience with managing Python projects using uv, you can use the questions and answers below to check your understanding and recap what you’ve learned.

These FAQs are related to the most important concepts you’ve covered in this tutorial. Click theShow/Hide toggle beside each question to reveal the answer.

You can install uv using a standalone installer or from PyPI using tools likepipx orpip. Depending on your operating system, you can also use tools like Homebrew and Cargo.

Yes, uv automatically creates and manages virtual environments for your projects.

You can build a package using theuv build command, and publish it to a package repository like PyPI or a private index with theuv publish command.

Yes, uv allows you to install and manage multiple Python versions within your projects using theuv python install command. However, because Python doesn’t publish official distributable binaries, uv uses distributions from the Astral project.

Take the Quiz: Test your knowledge with our interactive “Managing Python Projects With uv: An All-in-One Solution” quiz. You’ll receive a score upon completion to help you track your learning progress:


Managing Python Projects With uv: An All-in-One Solution

Interactive Quiz

Managing Python Projects With uv: An All-in-One Solution

In this quiz, you'll test your understanding of the uv tool, a high-speed package and project manager for Python.

Recommended Course

Python Project Management With uv(48m)

🐍 Python Tricks 💌

Get a short & sweetPython Trick delivered to your inbox every couple of days. No spam ever. Unsubscribe any time. Curated by the Real Python team.

Python Tricks Dictionary Merge

AboutLeodanis Pozo Ramos

Leodanis is a self-taught Python developer, educator, and technical writer with over 10 years of experience.

» More about Leodanis

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

MasterReal-World Python Skills With Unlimited Access to Real Python

Locked learning resources

Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert Pythonistas:

Level Up Your Python Skills »

MasterReal-World Python Skills
With Unlimited Access to Real Python

Locked learning resources

Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert Pythonistas:

Level Up Your Python Skills »

What Do You Think?

Rate this article:

What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.

Commenting Tips: The most useful comments are those written with the goal of learning from or helping out other students.Get tips for asking good questions andget answers to common questions in our support portal.


Looking for a real-time conversation? Visit theReal Python Community Chat or join the next“Office Hours” Live Q&A Session. Happy Pythoning!

Keep Learning

Related Topics:intermediatetools

Related Courses:

Related Tutorials:

Keep reading Real Python by creating a free account or signing in:

Already have an account?Sign-In

Almost there! Complete this form and click the button below to gain instant access:

Managing Python Projects With uv: An All-in-One Solution

Managing Python Projects With uv: An All-in-One Solution (Sample Code)

🔒 No spam. We take your privacy seriously.


[8]ページ先頭

©2009-2026 Movatter.jp