Skip to main content

pyDefine

Convert Python errors into beginner-friendly explanations and guides you with actionable solutions

Python Version PyPI Version License: MIT Tests

pyDefine is a pure-Python developer library created by Yahya Mundewadi (Portfolio: yahya.in). pyDefine takes raw Python tracebacks and exceptions and converts them into clean, beginner-friendly explanations with actionable fix suggestions and source code context previews. Perfect for students, educators, and developers!


Features 🌟

  • 164+ Exception Types Covered - Comprehensive support for built-ins, Web APIs, Databases, Data Science (Pandas/NumPy), Asyncio, Security, and Validation errors.
  • 16 Core Categories - Structured categorization from Syntax, Types, and Math to Database, Network, and Concurrency.
  • Source Code Context Previews - Automatically reads target source lines and highlights the exact error line with a pointer (>).
  • Dynamic Class Inheritance Fallback - Custom and third-party library exceptions automatically inherit explanations from their base exception classes.
  • Actionable Fix Suggestions - Every error comes with an immediate, plain-English solution.
  • Multiple Interfaces - Use as a library (import pydefine), CLI tool (pydefine script.py), or interactive decoder.
  • Pure Python & Zero Dependencies - Fast, lightweight, and works anywhere Python runs.
  • Safe Code Execution - Built-in safe_run() for testing code snippets with live error decoding.
  • Production Ready - 100% test pass rate, type-hinted, and Ruff-linted.

Installation 📦

pip install --upgrade pydefine

From Source

git clone https://github.com/mdyahhya/pydefine.git
cd pydefine
pip install -e .

Quick Start 🚀

1. Global Exception Hook (Easiest)

Just enable pyDefine once at the start of your script or app:

import pydefine
pydefine.enable()

# Normal code - any uncaught exception will now show a clean card!
number = 10
divisor = 0
result = number / divisor

Output:

┌─ ➗ Error: ZeroDivisionError ──────────────────────────────────────────
│  Category : Arithmetic & Math
│  Message  : division by zero
│  Location : app.py:6
│
│  Summary  : Division or modulo operation by zero was attempted.
│  Fix      : Check if the divisor is zero before performing division.
│
│  Context  :
│          5 │ divisor = 0
│    >     6 │ result = number / divisor
└───────────────────────────────────────────────────────────── pyDefine ─

2. Manual Decoding in try/except

import pydefine

try:
    data = {"name": "Alice"}
    print(data["email"])
except Exception as e:
    pydefine.quick_decode(e)

3. Quick One-Liner Explanation

import pydefine

try:
    int("hello")
except Exception as e:
    print(pydefine.explain(e))
    # 🎯 ValueError: An argument received the correct data type but an invalid value.

Command Line Interface (CLI) 💻

Run scripts directly through pydefine with live diagnostic reports:

# Run a Python script with error diagnostics
pydefine script.py

# List all 16 categories
pydefine --list

# Filter exceptions by category
pydefine --category "Database & SQL"
pydefine --category "Web & HTTP APIs"

# List all 164+ exceptions
pydefine --list-all

Supported Categories 📂

  1. Syntax & Formatting (SyntaxError, IndentationError, TabError)
  2. Name & Scope (NameError, UnboundLocalError, AttributeError)
  3. Type & Value (TypeError, ValueError, KeyError, IndexError, LookupError, AssertionError)
  4. Arithmetic & Math (ZeroDivisionError, OverflowError, FloatingPointError, SingularMatrixError)
  5. File & Operating System (FileNotFoundError, PermissionError, OSError, SubprocessError)
  6. Import & Module (ImportError, ModuleNotFoundError, ZipImportError)
  7. Runtime & Recursion (RuntimeError, RecursionError, NotImplementedError, ExceptionGroup)
  8. Network & Connection (ConnectionError, BrokenPipeError, TimeoutError, URLError)
  9. Process & Lifecycle (MemoryError, BufferError, KeyboardInterrupt, SystemExit)
  10. Database & SQL (DatabaseError, OperationalError, IntegrityError, ProgrammingError, SQLAlchemyError)
  11. Web & HTTP APIs (JSONDecodeError, HTTPError, RequestException, RateLimitError)
  12. Data Science & Arrays (EmptyDataError, ParserError, AxisError, LinAlgError, ShapeError)
  13. Async & Concurrency (CancelledError, InvalidStateError, QueueEmpty, ThreadError)
  14. Security & Cryptography (SSLError, AuthenticationError, ForbiddenError, JWTError)
  15. Validation & Serialization (ValidationError, PydanticCustomError, SchemaError)
  16. Warnings & Deprecations (DeprecationWarning, RuntimeWarning, UserWarning, FutureWarning)

License 📜

This project is licensed under the MIT License - see the LICENSE file for details.


Author & Contact 📞


✨ Powered by pyDefine ● Created by Yahya Mundewadi (yahya.in)

Release files for pydefine 1.1.9

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

Source distribution (sdist)

Source distribution for pydefine 1.1.9
File Size Uploaded
pydefine-1.1.9.tar.gz 38.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydefine 1.1.9
File Interpreter ABI Platform
pydefine-1.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 74.2 kB

Release files / pydefine-1.1.9.tar.gz

Download URL pydefine-1.1.9.tar.gz
Size 38.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f8bd27f1092061e9f97a1d85ead496748f8a2a82420ff5bdf6141679d58f9d60
BLAKE2b-256 checksum
How to use checksums
acadfdd253d063db097f4d0efd18310faa363b032aabaa50c1bbf80b2672b5ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pydefine-1.1.9-py3-none-any.whl

Download URL pydefine-1.1.9-py3-none-any.whl
Size 35.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbee7b465fbf8c549a76468f2dd8a19f0b5b6267bb532f002274e02b50d8afe3
BLAKE2b-256 checksum
How to use checksums
511547877c9f612801850857de68d5452ef9db957eced04b3a0a535c0bdb0eed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

1.1.27

2 release files

1.1.26

2 release files

1.1.25

2 release files

1.1.24

2 release files

1.1.23

2 release files

1.1.22

2 release files

1.1.21

2 release files

1.1.20

2 release files

1.1.19

2 release files

1.1.18

2 release files

1.1.17

2 release files

1.1.16

2 release files

1.1.15

2 release files

1.1.14

2 release files

1.1.13

2 release files

1.1.12

2 release files

1.1.11

2 release files

1.1.10

2 release files

This release

1.1.9 This release

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

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