Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Useful Python Tidbits

Project description

Ever find yourself copying and pasting small chunks of Python code between a bunch of your projects? The goal of this library is to reduce or eliminate that problem.

Yes, I realize that’s never going to happen. Contributions are very appreciated though, let’s see how close we can get.

Latest PyPI Version CircleCI Test Status Python Version Support


$ pip install --upgrade tidbits

Note that in an effort to keep this library generalized, optional dependencies are not included, ie. for the Sentry integration you will still need to

$ pip install raven

For convenience, these are bundled as extra dependencies, ie. you can do

$ pip install --upgrade tidbits[gcloud,sentry]



> requires python-json-logger or tidbits[gcloud]

Have you ever run an app on Google Cloud and wondered why all your logs were marked as errors, regardless of log level? Well, most likely you weren’t formatting them correctly – Google Cloud expects JSON logs with “severity” rather than “levelname”, which you can set with:

from tidbits.gcloud.log import get_handler

# or, even better, set all your loggers at once with tidbits.log


Ever had to configure the loggers of all of your dependencies? This one’s for you.

from tidbits.log import get_all_loggers
from tidbits.log import get_all_base_loggers
from tidbits.log import set_handler
from tidbits.log import set_loglevel

import requests

# ['requests', 'urllib3', 'urllib3.connection', 'urllib3.connectionpool', 'urllib3.poolmanager', 'urllib3.response', 'urllib3.util', 'urllib3.util.retry']

# ['requests', 'urllib3']

set_handler(myCoolHandler, logger='applesauce')
# the "applesauce" logger uses this (and only this) handler
# all loggers use this (and only this) handler
set_handler_globally(myCoolHandler, ignore={'aardvark', 'banana'})
# all loggers except those listed use this (and only this) handler

# sets logging.getLogger() to DEBUG and all others to INFO
# sets logging.getLogger() to INFO and all others to WARNING


> requires raven or tidbits[sentry]

Do you use Sentry? I do. And every single project I use it in contains the same block for configuring it and instrumenting the error logger.

from tidbits.integration.sentry import SENTRY
from tidbits.integration.sentry import instrument_logger

except Exception:
    # damn, I totally didn't expect an error here, better send it to Sentry

# creates events in Sentry for each error log

Project details

Download files

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

Files for tidbits, version 0.4.1
Filename, size File type Python version Upload date Hashes
Filename, size tidbits-0.4.1-py2.py3-none-any.whl (6.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size tidbits-0.4.1.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

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