Skip to main content

Logs all imported packages and their version

Project description

ReadTheDocs Coveralls PyPI-Server

Border-Patrol

Border-Patrol logs all imported packages and their version to support you while debugging. In 95% of all cases when something suddenly breaks in production it is due to some different version in one of your requirements. Pinning down the versions of all your dependencies and dependencies of dependencies inside a virtual environments helps you to overcome this problem but is quite cumbersome and thus this method is not always applied in practice. Also sometimes, like when you are using PySpark, you might not be 100% sure which library versions are installed on some cluster nodes.

With Border-Patrol you can easily find the culprit by looking in the logs of the last working versions and compare it to the failing one since Border-Patrol will list all imported packages and their corresponding version right at the end of your application, even if it crashed.

Usage

Border-Patrol is really simple to use, just install it with pip install border-patrol and import it before any other package, e.g.:

from border_patrol import with_print_stdout

import pandas as pd

If you run those lines in a script, you will get a similar output to this one:

Python version is 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 14:01:38)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
Following packages were imported:
PACKAGE         VERSION   PATH
border_patrol   0.1       /Users/fwilhelm/Sources/border_patrol/src/border_patrol
cycler          0.10.0    /Users/fwilhelm/anaconda/envs/lib/python3.6/site-packages/cycler.py
dateutil        2.7.5     /Users/fwilhelm/anaconda/envs/lib/python3.6/site-packages/dateutil/__init__.py
matplotlib      2.2.3     /Users/fwilhelm/anaconda/envs/lib/python3.6/site-packages/matplotlib/__init__.py
numpy           1.15.1    /Users/fwilhelm/anaconda/envs/lib/python3.6/site-packages/numpy/__init__.py
pandas          0.23.4    /Users/fwilhelm/anaconda/envs/lib/python3.6/site-packages/pandas/__init__.py
pyparsing       2.3.0     /Users/fwilhelm/anaconda/envs/lib/python3.6/site-packages/pyparsing.py
pytz            2018.7    /Users/fwilhelm/anaconda/envs/lib/python3.6/site-packages/pytz/__init__.py
six             1.11.0    /Users/fwilhelm/anaconda/envs/lib/python3.6/site-packages/six.py

If you import with_print_stdout, Border-Patrol will use print as output function whereas with_print_stderr will print to standard error. Since most production applications will rather use the logging module, you can tell Border-Patrol to use it by importing with_log_{error|warning|info|debug}. For instance from border_patrol import with_log_info will log the final report by using the INFO logging level.

If you want even more fine grained control you can import the BorderPatrol class directly from the border_patrol package and use the register() and unregister() method to activate and deactivate it, respectively. At any point the tracking can be circumvented by using border_patrol.builtin_import.

How does it work?

Border-Patrol is actually quite simple. It overwrites the __import__ function in Python's builtins package to track every imported package. Additionally it registers an atexit handler to be called when your application finishes and reports all imported modules. To avoid any problem registering these things more than once, Border-Patrol is implemented as Singleton and thus it is not thread-safe.

Note

This project has been set up using PyScaffold 3.1. For details and usage information on PyScaffold see https://pyscaffold.org/.

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

border-patrol-0.1.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

border_patrol-0.1-py2.py3-none-any.whl (7.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file border-patrol-0.1.tar.gz.

File metadata

  • Download URL: border-patrol-0.1.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.8

File hashes

Hashes for border-patrol-0.1.tar.gz
Algorithm Hash digest
SHA256 a14c15a89174e1d468d2b1f27553cdc4dfe54ba4c034b2f17b88128fd0f59a06
MD5 2477b768bb5984f2839c0c5ff5cc7fe7
BLAKE2b-256 09e554bac6ebaec967a0acfb22ff1add7497a69a63226fd02e07138116c851dc

See more details on using hashes here.

File details

Details for the file border_patrol-0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: border_patrol-0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.8

File hashes

Hashes for border_patrol-0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 07b3ce719b3719bfda8e0a4dd11c6aa436c55fe84a6841337a8d5bd55b14eb9f
MD5 81b07044adf9e2328db91945792091c1
BLAKE2b-256 efabfb0c2417eb5a98bf55ba9c81867393223602f0e80ea5a1eff5ce6d72398b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page