Skip to main content

A linter to manage your exception like a PRO!

Project description

Prevent Exception Handling AntiPatterns in Python

Actions Status PyPI Semantic Release GitHub Downloads Code style: black try/except style: tryceratops Open in Visual Studio Code Follow guilatrova

Inspired by this blog post. I described the building process of this tool here.

“For those who like dinosaurs 🦖 and clean try/except ✨ blocks.”


Installation and usage


pip install tryceratops


tryceratops [filename or dir...]

You can enable experimental analyzers by running:

tryceratops --experimental [filename or dir...]

You can ignore specific violations by using: --ignore TCXXX repeatedly:

tryceratops --ignore TC201 --ignore TC202 [filename or dir...]

You can exclude dirs by using: --exclude dir/path repeatedly:

tryceratops --exclude tests --exclude .venv [filename or dir...]

You can also autofix some violations:

tryceratops --autofix [filename or dir...]


flake8 Plugin

🦖 Tryceratops is also a plugin for flake8, so you can:

❯ flake8 --select TC src/tests/samples/violations/
src/tests/samples/violations/ TC002 Create your own exception
src/tests/samples/violations/ TC003 Avoid specifying long messages outside the exception class
src/tests/samples/violations/ TC201 Simply use 'raise' without specifying exception object again


All violations and its descriptions can be found in docs.

Autofix support

So far, autofix only supports violations: TC200, TC201, and TC400.

Ignoring violations

If you want to ignore a violation in a specific file, you can either:

  • Add a comment with noqa to the top of the file you want to ignore
  • Add a comment with noqa to the line you want to ignore
  • Add a comment with noqa: CODE to the line you want to ignore a specific violation


def verbose_reraise_1():
        a = 1
    except Exception as ex:
        raise ex  # noqa: TC202


You can set up a pyproject.toml file to set rules. This is useful to avoid reusing the same CLI flags over and over again and helps to define the structure of your project.


exclude = ["samples"]
ignore = ["TC002", "TC200", "TC300"]
experimental = true

CLI flags always overwrite the config file.


If you wish to use pre-commit, add this:

  - repo:
    rev: v1.1.0
      - id: tryceratops

Show your style

try/except style: tryceratops

Add this fancy badge to your project's

[![try/except style: tryceratops](](

Extra Resources

If you want to read more about:


Thank you for considering making Tryceratops better for everyone!

Refer to Contributing docs.

Change log





Thanks to God for the inspiration 🙌 ☁️ ☀️

The black project for insights.

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

tryceratops-1.1.0.tar.gz (19.8 kB view hashes)

Uploaded source

Built Distribution

tryceratops-1.1.0-py3-none-any.whl (25.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page