Home ¦ Posts ¦ Books ¦ Articles ¦ Talks ¦ Notes > Category: python ¦ Atom

Posts on python

Monitoring Python applications with Prometheus

I recently wrote two articles on Python application monitoring with Prometheus:

The demos can be found in the python-prometheus-demo repository.

Also checkout aiohttp-prometheus.


Doing Math with Python Humble Bundle

Humble bundle


Introducing distributed tracing in your Python application via Zipkin

Distributed tracing is the idea of tracing a network request as it travels through your services, as it would be in a microservices based architecture. The primary reason you may want to do is to troubleshoot or monitor the latency of a request as it travels through the different services …


QueueLogger and Python JSON Logger

Using QueueLogger with Python JSON Logger

When logging from multiple processes (via multiprocessing module), using QueueHandler is one approach with Python 2.

QueueHandler however sets exc_info attribute of a LogRecord to None since it is not "pickleable" (more on this later). This becomes a problem when you use python-json-logger to …


Presentation slides with Jupyter Notebook

I presented at the PyCon 2016 Education Summit on "Doing Math with Python" day before yesterday and a lightning talk yesterday. This is the first time, I prepared a slide deck using Jupyter Notebook + Reveal.js. I was pleased with the content creation process and the end result. So, here …


Webucator video: Python classes - basics beyond the absolute basics

Webucator recently created a video based on my Python classes: basics beyond the absolute basics article.

You can see the video on YouTube or here below:

I think they really did a great job with it and supplements my article well.


Replacing boto S3 mocks using moto in Python

Let's say you have some Python application code which connects to Amazon S3 which retrieves the keys in a bucket. Very likely, the application would be using boto and the code would like this:

import boto

def get_s3_conn():
    return boto.connect_s3('<aws-access-key', '<aws-secret-key>')

def list_keys():
    s3_conn = get_s3_conn()
    b = s3_conn.get_bucket …

tempfile.NamedTemporaryFile() in Python

In Python, when you need to create a temporary file with a filename associated to it on disk, NamedTemporaryFile function in the tempfile module is the goto function. Here are some use cases that I think one might use it for.

Case #1: You simply need a named empty temporary …


Mock objects and non-existent attributes/methods in Python

Updated: Fixed typo in the last paragraph.

Today, I was curious to see this behavior of Mock() objects when using mock:

>>> from mock import Mock
>>> m = Mock()
>>> m.i_dont_exist
<Mock name='mock.i_dont_exist' id='139841609578768'>
>>> m.i_dont_exist()
<Mock name='mock.i_dont_exist()' id='139841609106896'>

The above is expected, since I have …


A virtualenv first approach to Python projects

I have until the last few months (of my ~4 years of working with Python) always worked without virtualenv for all my Python projects. Why? I think I found the whole idea of having to do the following two steps before I work on something cumbersome:

  • Remember the exact virtualenv …

© Amit Saha. Built using Pelican. Customised theme based on the one by Giulio Fidente on github.