Skip to main content

Library of web access log analysis

Project description

alternate text

Travis CI build status

Lala is a Python library for access log analysis. It provides a set of methods to retrieve, parse and analyze access logs (only from NGINX for now), and makes it easy to plot geo-localization or time-series data. Think of it as a simpler, Python-automatable version of Google Analytics, to make reports like this:

alternate text


from lala import WebLogs
weblogs, errored_lines = WebLogs.from_nginx_weblogs('access_logs.txt')

Similarly, to fetch logs on a distant server (for which you have access keys) you would write:

from lala import get_remote_file_content, WebLogs

logs= lala.get_remote_file_content(
    host="", user='root',
weblogs, errors = WebLogs.from_nginx_weblogs(logs.split('\n'))

Now weblogs is a scpecial kind of Pandas dataframe where each row is one server access, with fields such as IP, date, referrer, country_name, etc.

alternate text

The web logs can therefore be analyzed using any of Pandas’ built-in filtering and plotting functions. The WebLogs class also provides additional methods which are particularly useful to analyse web logs, for instance to plot pie-charts:

ax, country_values = weblogs.plot_piechart('country_name')
alternate text

Next we plot the location (cities) providing the most connexions:

ax = weblogs.plot_geo_positions()
alternate text

We can also restrict the entries to the UK, and plot a timeline of connexions:

uk_entries = weblogs[weblogs.country_name == 'United Kingdom']
ax = uk_entries.plot_timeline(bins_per_day=2)
alternate text

Here is how to get the visitors a list of visitors and visits, sort out the most frequent visitors, find their locations, and plot it all:

visitors = weblogs.visitors_and_visits()
visitors_locations = weblogs.visitors_locations()
frequent_visitors = weblogs.most_frequent_visitors(n_visitors=5)
ax = weblogs.plot_most_frequent_visitors(n_visitors=5)
alternate text

Lala can do more, such as identifying the domain name of the visitors, which can be used to filter out the robots of search engines:

filtered_entries = weblogs.filter_by_text_search(
    terms=['googlebot', '', 'baidu', 'msnbot'],

Lala also plays nicely with the PDF Reports library to let you define report templates such as this one (written in Pug), and then generate this PDF report with the following code:



You can install lala through PIP

sudo pip install python-lala

Alternatively, you can unzip the sources in a folder and type

sudo python install

For plotting maps you will need Cartopy which is not always easy to install - it may depend on your system. If you are on Ubuntu 16+, first install the dependencies with:

sudo apt-get install libproj-dev proj-bin proj-data libgeos-dev
sudo pip install cython

License = MIT

lala is an open-source software originally written at the Edinburgh Genome Foundry by Zulko and released on Github under the MIT licence (Copyright 2018 Edinburgh Genome Foundry).

Everyone is welcome to contribute!

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

python-lala-0.1.4.tar.gz (25.8 kB view hashes)

Uploaded source

Built Distribution

python_lala-0.1.4-py3-none-any.whl (9.8 kB view hashes)

Uploaded py3

Supported by

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