Skip to main content

sql-sp-harness

PyPI version Python 3.10|3.12|3.13

sql-sp-harness

T-SQL Stored Procedure Debug Harness — turn SQL Server stored procedures into safe, runnable debug scripts you can execute on a pre-production database without writing to real tables.

Documentation site: https://deeprajdeveloper.github.io/sql-sp-harness/ (GitHub Pages). Site styles live in docs/scss/; compile with npx sass docs/scss/styles.scss docs/scss/css/styles.css. CI syncs docs/version.json from the package via python3 scripts/sync_docs_version.py before each Pages deploy.

Not a live debugger. This tool generates a static test harness (DML previews + EXEC PRINT stubs + variable traces), not breakpoints or step-into debugging.

Not affiliated with Microsoft. "SQL Server" and T-SQL are used descriptively only.

What it does

Command Purpose
analyze See what keyword elements that procedure contains along with counts — DML, TRY/CATCH, loops, SET, line-level detail
generate Create a debug harness: real-table DML → SELECT previews, nested EXEC → PRINT stubs, PRINT traces on variables

Output includes a banner on the top of the procedure stating: DEBUG HARNESS — DO NOT RUN ON PRODUCTION.

Install

macOS / Linux:

pip install sql-sp-harness
# or: pip3 install sql-sp-harness

Windows:

py -m pip install sql-sp-harness

Requires Python 3.10+.

Verify (console script or module):

sql-sp-harness version
# alias: sp-harness version

python3 -m sql_sp_harness version   # macOS / Linux
py -m sql_sp_harness version        # Windows

Quick start

sql-sp-harness analyze -i MyProc.sql
sql-sp-harness generate -i MyProc.sql -o MyProc_debug.sql

With traces in the Messages tab (default):

sql-sp-harness generate -i MyProc.sql -o MyProc_debug.sql --trace-style print

By default, generate removes original line (--) and block (/* */) comments from the output. Use --keep-comments to preserve them (harness [DBG-*] markers are always added).

Script preparation

Deploy preamble (IF EXISTS … DROP PROCEDURE, standalone DROP PROCEDURE, SET ANSI_NULLS, SET QUOTED_IDENTIFIER) is removed for both analyze and generate. Only SSMS-style deploy blocks are stripped — in-procedure IF EXISTS (SELECT … FROM …) checks (including multi-line predicates) are kept.

generate also rewrites CREATE PROCEDURE into DECLARE parameters so the script does not create the procedure on the server.

Nested EXEC stubbing

generate replaces in-procedure EXEC / EXECUTE calls (including multi-line parameter lists) with [DBG-EXEC] PRINT stubs that show:

  • which stored procedure would run
  • the full runnable EXEC … command with parameter assignments
  • runtime values for @ parameters via PRINT CONCAT

Example output:

-- [DBG-EXEC] Would have executed stored procedure dbo.proc_name2
PRINT N'[DBG-EXEC] Procedure: dbo.proc_name2';
PRINT N'[DBG-EXEC] Command: EXEC dbo.proc_name2 @fld1 = @fld1, @fld2 = @fld2';
PRINT N'[DBG-EXEC] Parameters:';
PRINT CONCAT(N'[DBG-EXEC] @fld1 = ', CAST(@fld1 AS NVARCHAR(4000)));

--no-stub-dml skips DML replacement but still stubs nested EXEC calls. Dynamic SQL (EXEC(@sql), sp_executesql) is not rewritten.

Analyze options

sql-sp-harness analyze -i MyProc.sql --report MyProc.txt   # plain-text file
sql-sp-harness analyze -i MyProc.sql --plain               # no ANSI colors on terminal
sql-sp-harness analyze -i MyProc.sql --full                # show zero-count sections

Step log (audit trail)

Use --log to write a timestamped log beside the input (MyProc.log), or --log-file path/to/run.log for a custom path. Works with both analyze and generate.

Each line uses the format [datetime] [function_name] [LEVEL] message. INFO lines mark milestones (file read, preamble strip, transform complete); DEBUG lines list per-line edits (comment removal, DML stubs, EXEC stubs, trace injection, preamble removal). Functions include strip_deploy_preamble, strip_comments, _apply_line_edits, inject_traces, and others.

sql-sp-harness generate -i MyProc.sql -o MyProc_debug.sql --log
sql-sp-harness analyze -i MyProc.sql --log-file /tmp/myproc-analyze.log

With --log, progress still prints to stderr unless you also pass --quiet (the log file always receives full detail).

Development

git clone https://github.com/DeeprajDeveloper/sql-sp-harness.git
cd sql-sp-harness
pip install -e ".[dev]"
pytest

Sample SQL files for manual testing live under samples/ (e.g. samples/sample1.sql, samples/sql/enterprise_complex_proc.sql).

Build for PyPI:

./scripts/publish-pypi.sh
./scripts/publish-pypi.sh upload

When bumping the package version, also run python3 scripts/sync_docs_version.py so the docs site version badge stays in sync.

File encoding

SSMS often saves scripts as UTF-16 LE (Unicode). Older Windows exports may use Windows-1252 (smart quotes, en-dashes). The CLI auto-detects these; output is always UTF-8. Override with --encoding if needed:

sql-sp-harness generate -i MyProc.sql -o MyProc_debug.sql --encoding utf-16-le

Limitations

Pattern Behavior
Dynamic SQL Not analyzed
Encrypted procedures No source
Cursors Not rewritten
DDL inside proc Not stubbed
Dynamic EXEC (EXEC(@sql), sp_executesql) Not rewritten
Nested EXEC calls Replaced with [DBG-EXEC] PRINT stubs
SSMS deploy preamble Stripped; in-procedure IF EXISTS preserved

Always review generated scripts before running them on the database server.

License

MIT

Metadata

Release files for sql-sp-harness 1.0.6

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

Source distribution (sdist)

Source distribution for sql-sp-harness 1.0.6
File Size Uploaded Provenance Actions
sql_sp_harness-1.0.6.tar.gz 33.9 kB With provenance Details for sql_sp_harness-1.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sql-sp-harness 1.0.6
File Interpreter ABI Platform Actions
sql_sp_harness-1.0.6-py3-none-any.whl Python 3 none any Details for sql_sp_harness-1.0.6-py3-none-any.whl

Total release size: 71.6 kB

Release files / sql_sp_harness-1.0.6.tar.gz

Download URL sql_sp_harness-1.0.6.tar.gz
Size 33.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d3b6e22ee6263056c51b759cea9e8cc86e86d1baf3a56654789de6eecd6e826c
BLAKE2b-256 checksum
How to use checksums
e9914e90585fa268b1b0ae6f0f1a7dc5076c184baffa8f58d2db2150bc2b656f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 6, 2026.

Transparency log

Release files / sql_sp_harness-1.0.6-py3-none-any.whl

Download URL sql_sp_harness-1.0.6-py3-none-any.whl
Size 37.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
155b7a869731aa819f123f4a57aef1c81794ce1c071eed0a9a45d7823a299a49
BLAKE2b-256 checksum
How to use checksums
433ed68bc8bc77e48ae000c11facd62c70badc179d984b60ada8b13289a26cf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 6, 2026.

Transparency log

Security for sql-sp-harness 1.0.6

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 sql_sp_harness-1.0.6.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 Jun 6, 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.

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