To install, do pip install giphy-ipython-magic
. The only dependencies are IPython
and requests
.
The magic can be loaded in two ways:
- Execute
%load_ext giphy_magic
. This must be run in every notebook where you want to use%giphy
. - Add
'giphy_magic'
toc.IPKernelApp.extensions
in your profile'sipython_kernel_config.py
file. This will cause the magic to be loaded into every notebook by default.
- The script attempts to read
$GIPHY_API_KEY
from the environment and defaults to the public beta key if that variable is not found. - The constant
RANDOM_ON_NO_MATCH
controls what happens when Giphy cannot match the given tag. If it isFalse
, then a message is displayed. If it isTrue
, a random GIF is shown instead. - The constant
MAX_RATING
controls the rating of the GIF returned by Giphy.
Developers can test their changes to giphy-ipython-magic
in many ways, but it may be easiest to use the accompanying Vagrantfile
. vagrant up
will initialize a virtual machine with all of the necessary dependencies. After it completes, connect to the VM with vagrant ssh
and run PYTHONPATH=/vagrant ipython notebook --ip=0.0.0.0 --no-browser
. You can then access the IPython notebook server at localhost:8888
. Running %load_ext giphy_magic
will load the extension. Note that it is necessary to restart the IPython notebook server to test changes to the giphy_magic
module.
This software is distributed under the MIT License. If you can make money off of it, good for you!