Keep your Ruff config consistent across multiple projects.
ruff-sync is a CLI tool that pulls a canonical Ruff configuration from an upstream pyproject.toml or ruff.toml (hosted anywhere — GitHub, GitLab, or any raw URL) and merges it into your local project, preserving your comments, formatting, and project-specific overrides.
- The Problem
- How It Works
- Quick Start
- Key Features
- Configuration
- CI Integration
- Example Workflow
- Detailed Check Logic
- Contributing
- Dogfooding
- License
If you maintain more than one Python project, you've probably copy-pasted your [tool.ruff] config between repos more than once. When you decide to enable a new rule or bump your target Python version, you get to do it again — in every repo. Configs drift, standards diverge, and your "shared" style guide becomes a polite suggestion.
| Ecosystem | Mechanism | Limitation for Ruff users |
|---|---|---|
| ESLint | Shareable configs — publish an npm package, then extends: ["my-org-config"] |
Requires a package registry (npm). Python doesn't have an equivalent convention. |
| Prettier | Shared configs — same npm-package pattern, referenced via "prettier": "@my-org/prettier-config" in package.json |
Same — tightly coupled to npm. |
| Ruff | extend — extend from a local file path (great for monorepos) |
Only supports local paths. No native remote URL support (requested in astral-sh/ruff#12352). |
Ruff's extend is perfect inside a monorepo, but if your projects live in separate repositories, there's no built-in way to inherit config from a central source.
That's what ruff-sync does.
┌─────────────────────────────┐
│ Upstream repo │
│ (your "source of truth") │
│ │
│ pyproject.toml │
│ [tool.ruff] │
│ target-version = "py310" │
│ lint.select = [...] │
└──────────┬──────────────────┘
│ ruff-sync downloads
│ & extracts [tool.ruff]
▼
┌─────────────────────────────┐
│ Your local project │
│ │
│ pyproject.toml │
│ [tool.ruff] ◄── merged │
│ # your comments kept ✓ │
│ # formatting kept ✓ │
│ # per-file-ignores kept ✓│
└─────────────────────────────┘
- You point
ruff-syncat the URL of your canonicalpyproject.toml. - It downloads the file, extracts the
[tool.ruff]section. - It merges the upstream config into your local
pyproject.toml— updating values that changed, adding new rules, but preserving your local comments, whitespace, and any sections you've chosen to exclude (likeper-file-ignores).
No package registry. No publishing step. Just a URL.
With uv (recommended):
uv tool install ruff-syncWith pipx:
pipx install ruff-syncWith pip:
pip install ruff-sync# Sync from a GitHub/GitLab repository (defaults to main/pyproject.toml)
ruff-sync https://github.com/my-org/standards
# Or a direct blob/file URL (auto-converts to raw)
ruff-sync https://github.com/my-org/standards/blob/main/pyproject.toml
# Clone from any git repository (using SSH or HTTP, defaults to --depth 1)
# You can use the --branch flag to specify a branch (default: main)
ruff-sync git@github.com:my-org/standards.git
ruff-sync ssh://git@gitlab.com/my-org/standards.git
# Or if configured in pyproject.toml (see Configuration), simply run:
ruff-sync
# Exclude specific sections from being overwritten using dotted paths
ruff-sync --exclude lint.per-file-ignores lint.ignore
# Check if your local config is in sync (useful in CI)
ruff-sync check https://github.com/my-org/standards
# Semantic check — ignore cosmetic differences like comments and whitespace
ruff-sync check --semanticRun ruff-sync --help for full details on all available options.
- 🏗️ Format-preserving merges — Uses tomlkit under the hood, so your comments, whitespace, and TOML structure are preserved. No reformatting surprises.
- 🌐 GitHub & GitLab URL support — Automatically converts GitHub/GitLab repository URLs or blob URLs to raw content URLs.
- 📥 Git clone support — If the URL starts with
git@or uses thessh://,git://, orgit+ssh://schemes,ruff-syncwill perform an efficient shallow clone (using--filter=blob:noneand--no-checkout) to safely extract the configuration with minimal network traffic. - 🛡️ Selective exclusions — Keep project-specific overrides (like
per-file-ignoresortarget-version) from being clobbered by the upstream config. - 🌍 Works with any host — GitHub, GitLab, Bitbucket, private SSH servers, or any raw URL that serves a
pyproject.tomlorruff.toml. - 🤖 CI-ready
checkcommand — Verify that your local config is in sync without modifying anything. Exits 1 if out of sync, making it perfect for pre-merge gates. (See detailed logic) - 🧠 Semantic mode — Use
--semanticto ignore cosmetic differences (comments, whitespace) and only fail on real value changes.
You can configure ruff-sync itself in your pyproject.toml:
[tool.ruff-sync]
# The source of truth for your Ruff configuration
upstream = "https://github.com/my-org/standards"
# Use simple names for top-level keys, and dotted paths for nested keys
exclude = [
"target-version", # Top-level [tool.ruff] key — projects target different Python versions
"lint.per-file-ignores", # Project-specific file overrides
"lint.ignore", # Project-specific rule suppressions
"lint.isort.known-first-party", # Every project has different first-party packages
"lint.flake8-tidy-imports.banned-api", # Entire plugin section — project-specific banned APIs
"lint.pydocstyle.convention", # Teams may disagree on google vs numpy vs pep257
]This sets the default upstream and exclusions so you don't need to pass them on the command line every time.
Note: Any explicitly provided CLI arguments will override the values in pyproject.toml.
Here are all the possible values that can be provided in [tool.ruff-sync] along with their explanations and defaults:
[tool.ruff-sync]
# The source of truth URL for your Ruff configuration. (Required, unless passed via CLI)
upstream = "https://github.com/my-org/standards"
# A list of config keys to exclude from being synced. (Default: ["lint.per-file-ignores"])
# Use simple names for top-level keys, and dotted paths for nested keys.
exclude = [
"target-version",
"lint.per-file-ignores",
]
# The branch, tag, or commit hash to use when resolving a Git repository URL. (Default: "main")
branch = "develop"
# A directory prefix to use when looking for a configuration file in a repository. (Default: "")
# Useful if the upstream pyproject.toml is not at the repository root.
path = "config/ruff"The check command is designed for use in CI pipelines. Add it as a step to catch config drift before it merges:
# .github/workflows/ci.yaml
- name: Check ruff config is in sync
run: |
ruff-sync check --semanticWith --semantic, minor reformatting of your local file won't cause a false positive — only actual rule or value differences will fail the check.
To see exactly what's drifted, omit --no-diff (the default) and the output will include a unified diff:
$ ruff-sync check --semantic
🔍 Checking Ruff sync status...
❌ Ruff configuration at pyproject.toml is out of sync!
--- local (semantic)
+++ upstream (semantic)
@@ -5,6 +5,7 @@
"select": [
+ "PERF",
"RUF",
...
]A typical setup for an organization:
- Create a "standards" repo with your canonical
pyproject.tomlcontaining your shared[tool.ruff]config. - In each project, run
ruff-syncpointing at that repo — either manually, in a Makefile, or as a CI step. - When you update the standard, re-run
ruff-syncin each project to pull the changes. Your local comments andper-file-ignoresstay intact.
# In each project repo:
ruff-sync https://github.com/my-org/python-standards
git diff pyproject.toml # review the changes
git commit -am "sync ruff config from upstream"While ruff-sync is designed to sync from any repository or URL of your choosing, this repository also provides a few curated configurations in the configs/ directory that you can use directly.
For example, to sync an exhaustive "kitchen-sink" configuration that explicitly enables all rules and documents them:
ruff-sync https://github.com/Kilo59/ruff-sync/blob/main/configs/kitchen-sink/ruff.tomlOr configure it using pyproject.toml so it's always the default for your local project:
[tool.ruff-sync]
upstream = "https://github.com/Kilo59/ruff-sync"
path = "configs/kitchen-sink"By default, ruff-sync requires an existing configuration file (pyproject.toml or ruff.toml) to merge into. If you are starting a fresh project and want to initialize it with your organization's Ruff settings, you can use the --init flag to scaffold a new file automatically.
# Create a new pyproject.toml (or ruff.toml) pre-configured with upstream settings
ruff-sync pull https://github.com/my-org/standards --initruff-sync seamlessly supports both pyproject.toml and standalone ruff.toml (or .ruff.toml) files. If your upstream source or your local target is a ruff.toml, it will automatically adapt and sync the root configuration rather than looking for a [tool.ruff] section.
When you run ruff-sync check, it follows this process to determine if your project has drifted from the upstream source:
flowchart TD
Start([Start]) --> Local[Read Local pyproject.toml]
Local --> Upstream[Download Upstream pyproject.toml]
Upstream --> Extract[Extract tool.ruff section]
Extract --> Exclude[Apply Exclusions]
Exclude --> Merge[Perform in-memory Merge]
subgraph Comparison [Comparison Logic]
direction TB
SemanticNode{--semantic?}
SemanticNode -- Yes --> Unwrap[Unwrap TOML objects to Python Dicts]
Unwrap --> CompareVal[Compare Key/Value Pairs]
SemanticNode -- No --> CompareFull[Compare Full File Strings]
end
Merge --> Comparison
CompareVal --> ResultNode{Match?}
CompareFull --> ResultNode
ResultNode -- Yes --> Success([Exit 0: In Sync])
ResultNode -- No --> Diff[Generate Diff]
Diff --> Fail([Exit 1: Out of Sync])
%% Styling
style Start fill:#4a90e2,color:#fff,stroke:#357abd
style Success fill:#48c774,color:#fff,stroke:#36975a
style Fail fill:#f14668,color:#fff,stroke:#b2334b
style ResultNode fill:#ffdd57,color:#4a4a4a,stroke:#d4b106
style Comparison fill:none,stroke:#9e9e9e,stroke-dasharray: 5 5,stroke-width:2px
style SemanticNode fill:#f4f4f4,color:#363636,stroke:#dbdbdb
To see ruff-sync in action, you can "dogfood" it on this project's own config.
Check if this project is in sync with its upstream:
./scripts/check_dogfood.shOr sync from a large upstream like Pydantic's config:
# Using a HTTP URL
./scripts/pull_dogfood.sh
# Using a Git URL
./scripts/gitclone_dogfood.shThis will download Pydantic's Ruff configuration and merge it into the local pyproject.toml. You can then use git diff to see how it merged the keys while preserving the existing structure and comments.
To revert the changes after testing:
git checkout pyproject.toml