Skip to main content

Sourcery Analytics

PyPI build, test, and publish docs code style docs


sourcery-analytics is a command line tool and library for statically analyzing Python code quality.

Get started by installing using pip:

pip install sourcery-analytics

This will install sourcery-analytics as a command-line tool.

To identify code quality issues:

sourcery-analytics assess path/to/file.py

Example:

sourcery-analytics assess sourcery_analytics/metrics
sourcery_analytics/metrics/cyclomatic_complexity.py:47: error: working_memory of cyclomatic_complexity is 34 exceeding threshold of 20
Found 1 errors.

To analyze a single Python file, use the analyze subcommand:

sourcery-analytics analyze path/to/file.py

Example:

sourcery-analytics analyze sourcery_analytics/analysis.py
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ Method                                      ┃ length ┃ cyclomatic_complexity ┃ cognitive_complexity ┃ working_memory ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ sourcery_analytics.analysis.analyze         │      5 │                     1 │                    0 │              8 │
│ sourcery_analytics.analysis.analyze_methods │      4 │                     1 │                    1 │             12 │
└─────────────────────────────────────────────┴────────┴───────────────────────┴──────────────────────┴────────────────┘

Alternatively, import and run analysis using the library:

from sourcery_analytics import analyze_methods
source = """
    def cast_spell(self, spell):
        if self.power < spell.power:
            raise InsufficientPower
        print(f"{self.name} cast {spell.name}!")
"""
analyze_methods(source)
# [{'method_qualname': '.cast_spell', 'method_length': 3, 'method_cyclomatic_complexity': 1, 'method_cognitive_complexity': 1, 'method_working_memory': 6}]

For more, see the docs.

Repoanalysis.com

You can see how hundreds of top projects measure across different code quality metrics and see how your priojects compare at repoanalysis.com

Developed by Sourcery

Sourcery Analytics was originally developed by the team at Sourcery. Sourcery is an automated coding assistant to help Python developers review and improve their code while they work. Sourcery has a built in library of 100+ core rules and you can extend it further to create custom rules for any scenario.

Metadata

Release files for sourcery-analytics 1.2.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 sourcery-analytics 1.2.1
File Size Uploaded Provenance Actions
sourcery-analytics-1.2.1.tar.gz 20.0 kB Without provenance Details for sourcery-analytics-1.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sourcery-analytics 1.2.1
File Interpreter ABI Platform Actions
sourcery_analytics-1.2.1-py3-none-any.whl Python 3 none any Details for sourcery_analytics-1.2.1-py3-none-any.whl

Total release size: 46.4 kB

Release files / sourcery-analytics-1.2.1.tar.gz

Download URL sourcery-analytics-1.2.1.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
80e586c5e261994c4be25f6d039177215fc424debcfb3b9b4b9387de13e803dd
BLAKE2b-256 checksum
How to use checksums
e631bc6008c0f110bf463f1b7321398722eb32d4d325416b3548d8617dff5e62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.9.9 Linux/5.15.0-1020-azure

Release files / sourcery_analytics-1.2.1-py3-none-any.whl

Download URL sourcery_analytics-1.2.1-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d0bcdaaafbcb1cf13f0f7baeaa90d0d819d520a7bd91a8527dbb3ed28b86d23
BLAKE2b-256 checksum
How to use checksums
d30aed6854e0b3bcf3428f359be15f7fe99b6328ce4d7b12fc94ebeaa6e6a351
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.9.9 Linux/5.15.0-1020-azure

Security for sourcery-analytics 1.2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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