Skip to main content

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

Installation

$ 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]

Usage

GCloud

> 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

logging.getLogger().addHandler(get_handler())
# or, even better, set all your loggers at once with tidbits.log

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

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

get_all_base_loggers()
# ['requests', 'urllib3']

set_handler(myCoolHandler, logger='applesauce')
# the "applesauce" logger uses this (and only this) handler
set_handler_globally(myCoolHandler)
# 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

set_loglevel(debug=True)
# sets logging.getLogger() to DEBUG and all others to INFO
set_loglevel(debug=False)
# sets logging.getLogger() to INFO and all others to WARNING

Integrations

> 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

try:
    {}['missing_key']
except Exception:
    # damn, I totally didn't expect an error here, better send it to Sentry
    SENTRY.captureException()

# creates events in Sentry for each error log
instrument_logger(level=logging.Error)

Metadata

Release files for tidbits 0.4.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 tidbits 0.4.1
File Size Uploaded
tidbits-0.4.1.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tidbits 0.4.1
File Interpreter ABI Platform
tidbits-0.4.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 12.1 kB

Release files / tidbits-0.4.1.tar.gz

Download URL tidbits-0.4.1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4d1fa9c60e267ffa00d626de8bb7e9e1aff75e7027dc1ae1e982e6fb60fce516
BLAKE2b-256 checksum
How to use checksums
32ac9e7d104388364fb4c93331297b1092fc2344b49083ae7a1a2e7c3aaff287
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release files / tidbits-0.4.1-py2.py3-none-any.whl

Download URL tidbits-0.4.1-py2.py3-none-any.whl
Size 6.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
393d147fe79763f9ec746b5c2492d63227887b451901cb27fb6201d08bd741df
BLAKE2b-256 checksum
How to use checksums
da7046d164c3d70526374de339540602b998d02692263f373b2be39fd2b151cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.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