Skip to main content

Python wrapper for PowerShell PSScriptAnalyzer - static analysis and formatting for PowerShell scripts

Project description

PyPI version License: MIT Code style: ruff Python Compatibility

py-psscriptanalyzer


Read the documentation on ReadTheDocs!


A Python wrapper for PSScriptAnalyzer - bringing PowerShell static analysis and formatting to your Python workflows!

What it does

Lints PowerShell files (.ps1, .psm1, .psd1) for code quality issues
Formats PowerShell code automatically
Works everywhere - Windows, macOS, Linux
Zero config - installs PSScriptAnalyzer automatically
GitHub Actions ready - with standard error annotations
CI/CD friendly - perfect for automation pipelines
Pre-commit hooks - catch issues before they hit your repo

Installation

pip install py-psscriptanalyzer

Usage

Command Line

# Analyze PowerShell files
py-psscriptanalyzer script.ps1 module.psm1

# Format PowerShell files
py-psscriptanalyzer --format script.ps1

# Set severity level
py-psscriptanalyzer --severity Error script.ps1

# Show all issues
py-psscriptanalyzer --severity All script.ps1

Python API

from py_psscriptanalyzer import run_script_analyzer, find_powershell

# Find PowerShell installation
powershell_cmd = find_powershell()

# Analyze files
exit_code = run_script_analyzer(
    powershell_cmd,
    ["script.ps1"],
    severity="Warning"
)

# Format files
exit_code = run_script_analyzer(
    powershell_cmd,
    ["script.ps1"],
    format_files=True
)

Pre-commit Hooks

Add this to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/thetestlabs/py-psscriptanalyzer
    rev: v0.1.0
    hooks:
      - id: py-psscriptanalyzer # Lint your PowerShell
      - id: py-psscriptanalyzer-format # Format your PowerShell

GitHub Actions

- name: Analyze PowerShell
  run: |
    pip install py-psscriptanalyzer
    py-psscriptanalyzer --severity Error **/*.ps1

Prerequisites

  • Python 3.9+
  • PowerShell (any version - we'll find it!)

Need PowerShell? Get it here:

Documentation

Full documentation available at py-psscriptanalyzer.thetestlabs.io

Contributing

Contributions welcome! See our development guide in the documentation.

License

MIT - see LICENSE file.

A tool for linting and formatting PowerShell code using PSScriptAnalyzer.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_psscriptanalyzer-0.1.0.tar.gz (109.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_psscriptanalyzer-0.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file py_psscriptanalyzer-0.1.0.tar.gz.

File metadata

  • Download URL: py_psscriptanalyzer-0.1.0.tar.gz
  • Upload date:
  • Size: 109.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for py_psscriptanalyzer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2ca7e8dcbc1967b8f67bea4e0b416cd5fe369bdd294cd98d2ea7cd367126e0dd
MD5 9798205a3fadaf35e59b555a2d0a7eff
BLAKE2b-256 846653f904347b61913023730ef9a0ab67c7861df75ec2210c6bf062738409af

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_psscriptanalyzer-0.1.0.tar.gz:

Publisher: release.yaml on thetestlabs/py-psscriptanalyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_psscriptanalyzer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_psscriptanalyzer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32c32db3f55d33e678266a8397985b3183d23522727d3f9d4cc3aab641bc86ec
MD5 2592c031ff6f15aae49c33cee03aefa1
BLAKE2b-256 986cd8526145812718f2eb261432c9fd0546761d1b1dd640e4566579b82396ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_psscriptanalyzer-0.1.0-py3-none-any.whl:

Publisher: release.yaml on thetestlabs/py-psscriptanalyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page