On GitHub, Qix-/better-exceptions has picked up 4.7k stars, Python. Pretty and useful exceptions in Python, automatically.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
[!WARNING]
Thank you to everyone who has taken an interest in this project since I released it. It is now archived.
better-exceptions was a throwaway module I wrote one night while toying with Starbound mods. Figured I'd
release it because it was quasi-useful to me, and it blew up on Reddit overnight and somehow made its way
into being critical infra for some people.
With the onslaught of AI, I no longer have any interest or motivation to deal with this project. Further,
PyPi has made it clear they don't want to help me recover my accounts since my support requests have gone
unanswered for several months. I couldn't release a new version of this if I wanted to. I don't write Python
anymore, anyway.
better-exceptions was never meant to be used in production. If you're using it in production, stop.
It's never been vetted.
Further, a result of me archiving this means there will be forks and other versions of this that pop up
on PyPi or other places. Be very careful. This has been a very hot target of automated activity, and
I wouldn't be surprised if someone would try to include malware in some of those forks. I've been, quite
famously, a target for such attacks.
This was a fun project, until it wasn't. I appreciate everyone's feedback, input and contributions over the
years.
- Josh
Pretty and more helpful exceptions in Python, automatically.
Usage
Install better_exceptions via pip:
pip install better_exceptions
And set the BETTER_EXCEPTIONS environment variable to any value:
export BETTER_EXCEPTIONS=1 # Linux / OSX
setx BETTER_EXCEPTIONS 1 # Windows
That's it!
Python REPL (Interactive Shell)
In order to use better_exceptions in the Python REPL, first install the package (as instructed above) and run:
$ python -m better_exceptions
Type "help", "copyright", "credits" or "license" for more information.
(BetterExceptionsConsole)
>>>
in order to drop into a better_exceptions-enabled Python interactive shell.
Advanced Usage
If you want to allow the entirety of values to be outputted instead of being truncated to a certain amount of characters:
Note that this uses an undocumented method override, so it is not guaranteed to work on all platforms or versions of Python.
Django Usage
In settings.py, add your new class to the MIDDLEWARE setting and update your logging configuration:
# ...
MIDDLEWARE = [
# ...
"better_exceptions.integrations.django.BetterExceptionsMiddleware",
]
# ...
from better_exceptions.integrations.django import skip_errors_filter
# if you don't want to override LOGGING because you want to change the default,
# you can vendor Django's default logging configuration and update it for
# better-exceptions. the default for Django 3.1.4 can be found here:
# https://github.com/django/django/blob/3.1.4/django/utils/log.py#L13-L63
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'skip_errors': {
'()': 'django.utils.log.CallbackFilter',
'callback': skip_errors_filter,
}
},
'handlers': {
'console': {
'level': 'INFO',
# without the 'filters' key, Django will log errors twice:
# one time from better-exceptions and one time from Django.
# with the 'skip_errors' filter, we remove the repeat log
# from Django, which is unformatted.
'filters': ['skip_errors'],
'class': 'logging.StreamHandler',
}
},
'loggers': {
'django': {
'handlers': [
'console',
],
}
}
}
example output:
Troubleshooting
If you do not see beautiful exceptions, first make sure that the environment variable does exist. You can try echo $BETTER_EXCEPTIONS (Linux / OSX) or echo %BETTER_EXCEPTIONS% (Windows). On Linux and OSX, the export command does not add the variable permanently, you will probably need to edit the ~/.profile file to make it persistent. On Windows, you need to open a new terminal after the setx command.
Check that there is no conflict with another library, and that the sys.excepthook function has been correctly replaced with the better_exceptions's one. Sometimes other components can set up their own exception handlers, such as the python3-apport Ubuntu package that you may need to uninstall.
Make sure that you have not inadvertently deleted the better_exceptions_hook.pth file that should be in the same place as the better_exceptions folder where all of your Python packages are installed. Otherwise, try re-installing better_exceptions.
You can also try to manually activate the hook by adding import better_exceptions; better_exceptions.hook() at the beginning of your script.
Finally, if you still can not get this module to work, open a new issue by describing your problem precisely and detailing your configuration (Python and better_exceptions versions, OS, code snippet, interpreter, etc.) so that we can reproduce the bug you are experiencing.
Does Qix-/better-exceptions have a project website?
No homepage URL was recorded for Qix-/better-exceptions in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
Does Qix-/better-exceptions have any tags?
TopGit's last sync did not record any GitHub topics for Qix-/better-exceptions. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on Qix-/better-exceptions?
The most recent commit recorded on Qix-/better-exceptions was 1 month ago, based on the GitHub push timestamp. The repository has 231 forks — one of the better signals of community interest.
Is Qix-/better-exceptions open source?
Yes — Qix-/better-exceptions ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/Qix-/better-exceptions.
What license does Qix-/better-exceptions use?
Qix-/better-exceptions is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
Where do I read more about Qix-/better-exceptions?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/Qix-/better-exceptions is the definitive source.
Read full README in the tab above.
Want a second opinion on better-exceptions?
Ask an AI that can read this page — one click and you get its take on better-exceptions.