Skip to content

Instantly share code, notes, and snippets.

@kolibril13
Created July 1, 2025 08:58
Show Gist options
  • Save kolibril13/5bbace6afedc4b1d28da4d46df0153bc to your computer and use it in GitHub Desktop.
Save kolibril13/5bbace6afedc4b1d28da4d46df0153bc to your computer and use it in GitHub Desktop.
Cursor rule for running python scripts with uv
# Python Script Execution and Placement Rule
- Always run Python scripts using the command `uv run script.py`, where `script.py` is the name of the script.
All Python script tools must be placed in the project's ROOT folder. DO NOT create subfolders under any circumstances.
- Again, I repeat: use the "." (current directory); don't create subfolders. Also, do not create subfolders with the same name as the current folder.
- Do not ask, "Would you like to run the script now to see the output?" Just run it.
# Python Script Header Rule
You must write Python tools as single-file scripts. Each file must begin with the following header, placed at the very first line:
```python
# /// script
# requires-python = ">=3.12"
# ///
```
These files can include dependencies on libraries such as numpy.
If your script depends on third-party libraries, add a dependencies section inside the same header comment. Example:
```
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "numpy",
# "sqlite-utils",
# ]
# ///
```
Always ensure this block appears at the very top of the file, even when editing existing scripts.
'Numpy' is just a package name for illustration. Only use numpy when required.
With these self-contained scripts, you do not need to run `uv pip install numpy`. Simply run the script; installation will be done by uv in the background.
# Python Script Rules
- Do not use a main() function; write the Python script itself.
@vishalsachdev
Copy link

thanks for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment