Skip to main content

Profile Pruner

The tool that finally lets you deploy Salesforce Profiles across environments without second thoughts.

Profile Pruner removes every reference to metadata that does not exist in a target org from a Profile .profile-meta.xml file, so it deploys cleanly on the first try. It is dry-run by default — the org is never modified unless you explicitly pass --deploy-on-success. The result is a COMMON package (a profile that deploys cleanly, plus a toDeploy.xml manifest of the deployable members) and a MISSING package (the list of everything that was removed / is missing).

Why it exists

A profile exported from a source org (or a managed package org) often references objects, fields, tabs, classes, flows, login flows, layouts, record types, agents, enhanced summaries, etc. that do not exist in the target org. Deploying such a profile fails. Profile Pruner finds those references one by one and strips them.

You have three ways to feed it a profile:

  • via 1 — from a file (-pp/--profile-path + -do/--dest-org): prune a .profile-meta.xml you already have.
  • via 2 — from an org (-so/--src-org + -sp/--src-profile + -do + -dp): retrieve the profile from the source org, prune it against the destination org, then dry-run or deploy.
  • via 3 — retrieve only (-so/--src-org + -sp/--src-profile): just download the profile from the source org — no prune, no dry-run, no deploy. You can then feed the retrieved file to via 1, or run via 2 with -so == -do and -sp == -dp to prune it.

Alignment (--align-from-source): upgrades via 1 or via 2 into a profile alignment. It prunes the source profile against the destination, then retrieves and prunes the destination profile too, and turns OFF every permission that exists only in the destination (hidden tab/app, disabled field/object/class/page/flow) so the destination matches the source. This lets you align, for example, a UAT profile to a test profile. It runs automatically (no Y/N prompt): the pre-align destination profile is always saved in the run folder (2-destination-retrieved/), so the operation is reversible.

The alignment merge is source-authoritative: every source entry is kept verbatim, and every destination-only entry is turned OFF with an explicit off value (a Profile deploy is a per-element merge, so omitting an entry is a silent no-op). Sections with no expressible off value (layoutAssignments, loginFlows, loginIpRanges, loginHours) cannot be turned off by a deploy, so their destination-only entries are listed in MANUAL-OPERATIONS.txt for a manual Setup action. The merged profile is re-validated with a dry-run before any deploy — the deploy is attempted only when that dry-run is clean.

The third-party sf-profile-full plugin is no longer required. To use via 2 you need the Salesforce CLI installed with Node.js and its global node_modules (@salesforce/core + @jsforce/jsforce-node), which any recent sf installation already ships.

The retrieved (or provided) profile may still reference metadata that does not exist in the destination org (for example tabVisibilities for tabs that are not available), which causes deploy errors. Profile Pruner cleans exactly those leftover references.

How it works

  1. The profile is split by its top-level sections (classAccesses, fieldPermissions, tabVisibilities, layoutAssignments, …) — the sections are discovered dynamically from the XML, not hardcoded.
  2. Metadata API pre-pass (new in 1.11): before anything is deployed, the tool enumerates the metadata that actually exists in the target org with sf org list metadata (one call per type) and removes every reference that has no matching component — login flows, agent access, enhanced summaries, flows, layouts, record types, and every other listable type — in one shot. This is much faster than discovering each missing reference through dry-runs and covers the newest Profile sections automatically. The per-section dry-run below remains the authoritative fallback.
  3. Up to --thread-number workers run in parallel (capped to the number of sections to prune); each worker takes one section and, in a loop:
    • builds a sub-package containing only that section,
    • starts an async dry-run (sf project deploy start --dry-run --async) and polls sf project deploy report until terminal,
    • removes every offending entry and, under a mutex, writes the cleaned entries and the removed ones back in their original order.
  4. The worker repeats until its section dry-runs clean, then takes the next section from the queue.
  5. COMMON/ and MISSING/ are assembled from the surviving entries, keeping the original document order.
  6. As a final safety check, the tool runs one last dry-run of the whole assembled package; only if it succeeds the outcome is SUCCESS. This final gate is self-healing: if the full package surfaces a reference the per-section pass missed — a login flow, or a brand-new metadata type — it removes it and re-validates until clean, instead of aborting on the first error.

Requirements

  • Python 3.9+
  • lxml (installed automatically by the scripts below)
  • Salesforce CLI (sf) — auto-discovered from PATH and common install locations, or pass --sf <path> explicitly
  • Node.js >= 18.11 — auto-detected and prepended to PATH, so the CLI works even when an old Node is the system default
  • An authenticated org (alias or username) that the CLI can reach

Installation

pip install sf-profile-pruner

This installs the package, its dependency (lxml) and the sfpp command.

sfpp --help

The sfpp command is a real console-script executable (not a .cmd batch file), so pressing Ctrl-C goes straight to the program — cmd.exe never shows its "Terminate batch job (Y/N)?" prompt.

sfpp not recognized after install? This usually means the Python Scripts folder is not on your PATH. See INSTALLATION.md for a full step-by-step Windows guide (including the GUI method that works in Constrained Language Mode), or use python -m prune_profile as a PATH-independent fallback.

From the repository

One-time setup that installs the package + dependency, creates the sfpp command, checks Node.js and the Salesforce CLI, and puts sfpp on your PATH:

python first_config.py

Then open a new terminal and run:

sfpp --help

first_config runs pip install . under the hood, so it also resolves the lxml dependency. Re-run it after updating the tool to refresh the installed copy.

Requirements checked at setup time (and auto-discovered at run time if missing): a compatible Node.js (>= 18.11) and the Salesforce CLI (sf). first_config reports their exact location, or what is missing.

Usage

# via 1 — prune a profile file and dry-run against the destination org
sfpp -pp "path/to/My Profile.profile-meta.xml" -do myorg

# via 1 — deploy the cleaned profile (renamed) to the destination org
sfpp -pp "path/to/My Profile.profile-meta.xml" -do prod -dp "My Profile Clean" --deploy-on-success

# via 1 — same, but skip the Y/N confirmation
sfpp -pp "path/to/My Profile.profile-meta.xml" -do prod -dp "My Profile Clean" --deploy-on-success --sure

# via 2 — retrieve from a source org, prune, deploy to the destination org
sfpp -so devorg -sp "My Profile" -do mysandbox -dp "My Profile" --deploy-on-success

# via 3 — retrieve only (no prune): download the profile from a source org
sfpp -so devorg -sp "My Profile" -od ./profiles

Or, without the sfpp launcher, replace sfpp with python -m prune_profile.

Behaviour

  • Dry-run by default: the org is never modified.
  • --deploy-on-success: after the profile is clean, deploy it to the org.
  • Live progress board: during pruning, the console shows a live board with two worker cells per line, each with columns [Tx] status | tag | operation | [deleted/initial], plus a summary line with the elapsed time (hh:mm:ss) and the tag counters (done / running / todo). The [deleted/initial] column auto-widens when the counters grow (e.g. with -bs 1000/10000) so the two columns stay aligned. The elapsed clock ticks every second even while the workers are just polling. The full timestamped log still goes to run.log, and a final summary is printed at the end.
  • Ctrl-C stops cleanly: the run prints Saving pending work..., saves all pending work (the removals applied so far are kept), keeps the board rows on screen, marks the active threads "stopped by user", and reports ABORTED. The sf child is invoked as node run.js (not through the cmd.exe batch shim), so Ctrl-C can never trigger cmd's "Terminate batch job" prompt.
  • Metadata API pre-pass: before the dry-run loop, the tool enumerates the metadata that actually exists in the target org (sf org list metadata) and removes every dangling reference in one shot — login flows included.
  • Standard metadata pre-pass: the tool also queries the org's Tooling API (TabDefinition, EntityDefinition, FieldDefinition) and removes standard tabs, objects and fields the profile references but the org does not have. This catches the class of error a dry-run never surfaces — e.g. You can't edit tab settings for X, as it's not a valid tab — where an object exists but has no editable tab.
  • Self-healing final gate: the final full-package dry-run loops — any residual reference (a login flow, or a metadata type not yet in the internal map) is removed and the package re-validated until clean, rather than aborting on the first error.
  • Batch removal: every component failure reported by a single deploy is resolved and removed in one pass (not one error per run).
  • Alignment report (--align-from-source): the merged profile lives in 4-merged/ together with MANUAL-OPERATIONS.txt (sections with no deploy-able "off" value) and what-is-changed.txt (the full diff the deploy will apply, split into GRANTED / REVOKED / MANUAL sections, each changed field annotated with old value from <org>: <value>).
  • Merged-profile validation: before any deploy, the merged profile is dry-run against the destination; the deploy only runs when that dry-run is clean, otherwise the run ends with VALIDATION_FAILED.
  • Resumable: if it stops (network hiccup, unexpected error), run the exact same command again and it continues from the last error — nothing is redone.
  • Already clean: if a previous run ended with SUCCESS and you launch it again on the same output directory, it exits immediately with "profile already clean".
  • --fresh: restart from the original profile, ignoring any previous state.

Options

Options are grouped in the -h help. The two input modes are:

  • via 1 (file): -pp/--profile-path + -do/--dest-org
  • via 2 (org): -so/--src-org + -sp/--src-profile + -do + -dp
  • via 3 (retrieve only): -so/--src-org + -sp/--src-profile
Option Description
-pp, --profile-path Path of the source .profile-meta.xml file (via 1).
-so, --src-org Source org alias/username to retrieve from (via 2).
-sp, --src-profile Name of the Profile to retrieve from --src-org (via 2).
-fp, --full-profile Retrieve the full (non-stripped) profile; default is a clean retrieve (loginIpRanges/loginHours/userLicense removed).
-do, --dest-org Destination org alias/username (dry-run and optional deploy target). Optional: omit it (with -so + -sp) for retrieve only.
-dp, --dest-profile Name to deploy the cleaned profile under; created if it does not exist. Default: the source profile name.
-od, --out-dir Output directory for report/packages/logs. Default: the current directory.
-bs, --batch-size Split a section into chunks of N entries (min 100, max 10000, default 200); 0 disables splitting.
-tn, --thread-number Max parallel workers, 1–64. Default: 16.
--job-timeout Minutes to wait for a deploy job before aborting (1–60; 0 = no timeout). Default: 0.
-av, --api-version Manifest API version. Default: detected from the destination org.
--deploy-throttle-ms Min interval between deploy starts, in ms. Default: 500; 0 disables.
--poll-interval Seconds between status polls of a deploy job. Default: 3.
--max-iter Iteration cap. Default: 5000.
--sf Path to the Salesforce CLI. Default: sf.
--deploy-on-success Deploy the cleaned profile to --dest-org once pruning succeeds. Modifies the org: asks for Y/N confirmation (No = dry-run only). Use as [--deploy-on-success [--sure]].
--sure Skip the Y/N confirmation of --deploy-on-success and deploy without asking. No effect without --deploy-on-success.
--align-from-source Align the destination profile to the source: turn OFF destination-only permissions. Works with via 1 or via 2. Runs automatically (no prompt); the pre-align destination profile is saved in the run folder.
--diff Compare the source profile against the destination profile and write a pure profile-to-profile diff report (diff/diff-report.txt). Read-only: no prune, no dry-run, no deploy. Works with via 1 or via 2.
--fresh Restart from the original, ignoring any previous state.
--quiet Suppress the progressive stdout output.
--tell-me-a-story Turbolino will tell you a fascinating story about code, algorithms and copyright.
-V, --version Show version and author.

Output layout (--out-dir)

out-dir/
├── ORIGINAL_<name>.profile-meta.xml   # untouched copy of the original
├── COMMON/
│   ├── <name>.profile-meta.xml          # clean, deployable profile
│   └── toDeploy.xml                     # manifest of the deployable (COMMON) members
├── MISSING/
│   └── package.xml                          # everything removed / missing
├── missing_log.txt                           # resumable line-by-line log
├── run.log                                  # progressive log copy
├── report.txt                               # final summary (OUTCOME: SUCCESS/ABORTED)
└── .work/                                   # internal temporary working area (removed at the end)

You don't need your own SFDX project: the tool always creates a minimal one (sfdx-project.json only) under .work/project/, uses it for the deploy commands, and deletes it when finished.

Alignment output (--align-from-source)

When aligning, --out-dir is a run folder (one per invocation):

run/
├── 1-source-pruned/               # source pruned against the destination org
├── 2-destination-retrieved/       # destination profile retrieved from the org
├── 3-destination-pruned/          # destination pruned against itself
├── 4-merged/
│   ├── <name>.profile-meta.xml    # source-authoritative merged profile
│   ├── MANUAL-OPERATIONS.txt      # sections with no deploy-able "off" value
│   └── what-is-changed.txt        # the full diff the deploy will apply
└── run.log                        # full log

layoutAssignments manual operations are auto-classified in both reports: REDUNDANT (ignorable) when the object has a single page layout (the assignment is necessarily the default), or NEEDS CHECK when the object has several layouts. This keeps you from chasing assignments that would have no effect.

Repository structure

The tool is a small Python package split into thematic modules:

prune_profile/
├── __init__.py     public package surface (re-exports)
├── __main__.py     lets you run `python -m prune_profile`
├── constants.py    identity/version, namespace and the error-type mapping
├── xmlio.py        profile XML + package/manifest file I/O
├── sfcli.py        Salesforce CLI integration + sf/Node discovery
├── board.py        console logging and the live progress board
├── state.py        thread-safe shared pruning state
├── engine.py       parallel per-section pruning workers
├── retrieve.py     native full-profile retrieve (readMetadata)
├── stage.py        prune-stage orchestration (workers + prefetch + board)
├── merge.py        alignment merge (source-authoritative) + reports
├── cli.py          command-line entry point (`main()`)
└── node/retrieve_profile.cjs  Node helper for readMetadata retrieval

Notes

  • The org is never modified unless you pass --deploy-on-success.
  • --quiet still writes report.txt, missing_log.txt and run.log.
  • The manifest API version is detected automatically from the target org (sf org display, latest supported) unless you pass --api-version explicitly.
  • The Metadata API pre-pass needs the connecting user to be able to see the metadata it lists (System Administrator recommended). Custom fields and custom objects are intentionally not enumerated (listMetadata does not return them), so those are still discovered and pruned by the authoritative dry-run. Standard tabs, objects and fields are covered by the Tooling API pre-pass.

Author

Made with <3 by Lorenzo D'Aleo — turbolino.dev@proton.me

This software is unofficial and is written under the AGPL-3.0 license; use at your own risk.

(ɔ) All Right Reversed!

License

GNU Affero General Public License v3.0 (AGPL-3.0) — see LICENSE.

Metadata

Release files for sf-profile-pruner 2.14.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sf-profile-pruner 2.14.1
File Size Uploaded Provenance Actions
sf_profile_pruner-2.14.1.tar.gz 100.9 kB With provenance Details for sf_profile_pruner-2.14.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sf-profile-pruner 2.14.1
File Interpreter ABI Platform Actions
sf_profile_pruner-2.14.1-py3-none-any.whl Python 3 none any Details for sf_profile_pruner-2.14.1-py3-none-any.whl

Total release size: 187.3 kB

Release files / sf_profile_pruner-2.14.1.tar.gz

Download URL sf_profile_pruner-2.14.1.tar.gz
Size 100.9 kB
Tags Source
SHA-256 checksum
How to use checksums
47e02d2afb83ebc53f48f869349abc513371cd9fb60021ccd408fa9848f8f97f
BLAKE2b-256 checksum
How to use checksums
dbd0e621f86704d49fda580439158e5ea2344026fae22b8f5194aea71ee424f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / sf_profile_pruner-2.14.1-py3-none-any.whl

Download URL sf_profile_pruner-2.14.1-py3-none-any.whl
Size 86.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e44f4a2b2a71fed8a2f58687a7521f8b9685b54bab638e8115c8f11e5fe2495
BLAKE2b-256 checksum
How to use checksums
a3760b44c74779af1781150e944bb4c27eb5f7a1ce3674a1acdeec75828e92d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for sf-profile-pruner 2.14.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sf_profile_pruner-2.14.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.14.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page