Rye for Python

Rye is a “comprehensive project and package management solution for Python” – let’s check it out!
Grab a cup of tea, pull up a chair and put to one side any cognitive bias you have! (Just because it’s built with Rust doesn’t mean you have to install Rust!!!).


I won’t regurgitate the excellent documentation from https://rye-up.com/ but what I will do is give a very short prelude and then a real world example which hopefully compliments what you see in the documentation.

Pip, Poetry, Wheel, Dist, TOML etc can be a lot to learn on top of the Python language itself. Then throw in virtual environments, versioning and you will typically have many people all doing things differently.

I’ve read people saying why is there a need for Rye, and why not use Poetry and so on. But hopefully this comment from Rye Discord helps?

A. Executor - bootstraps + installs python versions: `rye {fetch,toolchain,tools}`
B. Installer - install packages: `rye add`
C. Locker - creates a "lock file": `rye {sync,lock,pin}`
D. V-env manager - manages environments: `rye {sync,run,[un]install}`
E. App Runner - run packages w/entrypoints as apps: `rye {add,run}`
F. Script Runner - run custom scripts or tsks: `rye run <script-name>`
G. Packager - create wheels/zips: `rye buld`
H. Publisher - publish to pypi/pkg repo: `rye publish`
I. Project Manager - manage project metadata: `rye {init,add,remove,sync,show}`
J. Version Manager - manage bumping versions: `rye version`
K. Task Manager - manage shell-level tasks: `rye run <my-dev>`

So yes, Rye should exist ๐Ÿ˜„ A sincere Thank You!

pylang – Rye Discord

Once installed, do “rye init”

"Initialize a new or existing Python project with Rye"

This is my project “r1” – and if you follow the Rye documentation you’ll only see an example that uses __init__.py

I’ve added my own “main.py” and here’s the accompanying “pyproject.toml

  • r1 is the project name
  • main is the file name
  • greeting is the function name
hello = "r1:hello"
entry = 'r1.main:greeting'
โฏ tree -L 3
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements-dev.lock
โ”œโ”€โ”€ requirements.lock
โ””โ”€โ”€ src
    โ””โ”€โ”€ r1
        โ”œโ”€โ”€ __init__.py
        โ”œโ”€โ”€ main.py
        โ””โ”€โ”€ __pycache__

Let’s check out “main.py” :

# src/r1/main.py

def greeting():
    print("\nHello from greeting function inside src/r1/main.py!\n")

if __name__ == "__main__":

As you can see, there is a slight issue with a warning message on my installation, I’ve check the “issues” on GitHub and I can see this is being discussed. It’s just a warning about cloud/dropbox sync so not make or break!

โฏ tree -L 3
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements-dev.lock
โ”œโ”€โ”€ requirements.lock
โ””โ”€โ”€ src
    โ””โ”€โ”€ r2
        โ”œโ”€โ”€ hello.py
        โ”œโ”€โ”€ __init__.py
dev = { cmd = "flask --app ./src/r2/hello.py run" }
from flask import Flask

app = Flask(__name__)

def hello_world():
    return "<p>Hello, World!</p>"


I’m not here to persuade, but just to showcase what clearly has taken a lot of work and effort, and surely it is worth road testing, and/or contributing to or making constructive criticism?

The linter, and formatter alone are a great integration (Ruff), and if the Python world converges on Rye, or builds on it then surely it will benefit one and all?

โฏ rye
An Experimental Package Management Solution for Python

Usage: rye [COMMAND]

  add        Adds a Python package to this project
  build      Builds a package for distribution
  config     Reads or modifies the global `config.toml` file
  fetch      Fetches a Python interpreter for the local machine
  fmt        Run the code formatter on the project
  init       Initialize a new or existing Python project with Rye
  install    Installs a package as global tool
  lock       Updates the lockfiles without installing dependencies
  lint       Run the linter on the project
  make-req   Builds and prints a PEP 508 requirement string from parts
  pin        Pins a Python version to this project
  publish    Publish packages to a package repository
  remove     Removes a package from this project
  run        Runs a command installed into this package
  show       Prints the current state of the project
  sync       Updates the virtualenv based on the pyproject.toml
  toolchain  Helper utility to manage Python toolchains
  tools      Helper utility to manage global tools
  self       Rye self management
  uninstall  Uninstalls a global tool
  version    Get or set project version
  help       Print this message or the help of the given subcommand(s)

Previous article


Next article

Reverse byte order