Sebastian Raschka


I would be happy to hear your comments and suggestions.
Please feel free to drop me a note via twitter, email, or google+.


IPython magic function documentation - %watermark

I wrote this simple watermark IPython magic function to conveniently add date- and time-stamps to my IPython notebooks. Also, I often want to document various system information, e.g., for my Python benchmarks series.



Installation

The watermark line magic can be directly installed from my GitHub repository via


In [1]:
%install_ext https://raw.githubusercontent.com/rasbt/watermark/master/watermark.py


Installed watermark.py. To use it, type:
  %load_ext watermark



Loading the %watermark magic

To load the date magic, execute the following line in your IPython notebook or current IPython shell


In [2]:
%load_ext watermark



Usage

In order to display the optional watermark arguments, type


In [3]:
%watermark?
  %watermark [-a AUTHOR] [-d] [-n] [-t] [-z] [-u] [-c CUSTOM_TIME] [-v]
                 [-p PACKAGES] [-h] [-m] [-g]


IPython magic function to print date/time stamps 
and various system information.

watermark version 1.1.0

optional arguments:
  -a AUTHOR, --author AUTHOR
                        prints author name
  -d, --date            prints current date
  -n, --datename        prints date with abbrv. day and month names
  -t, --time            prints current time
  -z, --timezone        appends the local time zone
  -u, --updated         appends a string "Last updated: "
  -c CUSTOM_TIME, --custom_time CUSTOM_TIME
                        prints a valid strftime() string
  -v, --python          prints Python and IPython version
  -p PACKAGES, --packages PACKAGES
                        prints versions of specified Python modules and
                        packages
  -h, --hostname        prints the host name
  -m, --machine         prints system and machine info
  -g, --githash         prints current Git commit hash



Examples


In [4]:
%watermark


29/07/2014 23:57:31

CPython 3.4.1
IPython 2.1.0

compiler   : GCC 4.2.1 (Apple Inc. build 5577)
system     : Darwin
release    : 13.3.0
machine    : x86_64
processor  : i386
CPU cores  : 2
interpreter: 64bit



In [4]:
%watermark -d -t


29/06/2014 01:19:11 



In [5]:
%watermark -u -n -t -z


Last updated: Sun Jun 19 2014 01:19:12 EDT



In [6]:
%watermark -v


CPython 3.4.1
IPython 2.1.0



In [7]:
%watermark -m


compiler   : GCC 4.2.1 (Apple Inc. build 5577)
system     : Darwin
release    : 13.2.0
machine    : x86_64
processor  : i386
CPU cores  : 2
interpreter: 64bit



In [8]:
%watermark -v -m -p numpy,scipy


CPython 3.4.1
IPython 2.1.0

numpy 1.8.1
scipy 0.14.0

compiler   : GCC 4.2.1 (Apple Inc. build 5577)
system     : Darwin
release    : 13.2.0
machine    : x86_64
processor  : i386
CPU cores  : 2
interpreter: 64bit



In [5]:
%watermark -a "John Doe" -d -v -m -g


John Doe 29/07/2014 

CPython 3.4.1
IPython 2.1.0

compiler   : GCC 4.2.1 (Apple Inc. build 5577)
system     : Darwin
release    : 13.3.0
machine    : x86_64
processor  : i386
CPU cores  : 2
interpreter: 64bit
Git hash   : 374c439445125a61400d6e062a4474f7369a8714