<jupyter_start><jupyter_text>Configuring IPython  Finding configuration options IPython has many configurable attributes. These can be viewed using the `-h` flag to the command line applications:<jupyter_code>!ipython -h<jupyter_output><empty_output><jupyter_text>This is an important trick for finding out configuration info:        $> ipython [subcommand] --help-all | grep [-C context] PATTERN`--help-all` exposes everything configurable in IPython,there is a good chance you will find what you are looking for. A common configuration question is:> how do I disable the "Do you really want to exit" message when quitting with `Ctrl-d`?Well, logically this has to do with `exit`, so let's look for it:<jupyter_code>!ipython --help-all | GREP_COLOR='1;31;46' grep --color exit<jupyter_output><empty_output><jupyter_text>Which shows me that I can disable the confirmation for a single IPython session with    $> ipython --no-confirm-exit    or I can set the `TerminalInteractiveShell.confirm_exit=False` in a config file,to have it be the default behavior.  Configuration principles Here are the design principles of the IPython configuration system: * Configuration is always done using class attributes* Classes that have configurable attributes are subclasses of `Configurable`* Attributes that are configurable are typed traitlets objects (`Bool`, `Unicode`, etc.) that have `config=True`* In config files, configurable attributes can be set using the format `Class.attr_name=the_value`* At the command line, configurable attributes can be set using the syntax `--Class.attr_name=the_value`* At the command line, some attributes have shorthands of the form `--attr-name=value`* Values set at the command line have higher priority than those set in config files  The IPython Profile IPython has a notion of 'profiles' - these are directories that live in your IPYTHONDIR,which contain configuration and runtime information.Let's create the default profile<jupyter_code>!ipython profile create newprofile<jupyter_output><empty_output><jupyter_text>This creates a profile in your IPYTHONDIR (`ipython locate` is a quick way to see where your IPYTHONDIR is),and populates it with automatically generated default config files.<jupyter_code>!ipython locate profile default
!ipython locate profile newprofile<jupyter_output><empty_output><jupyter_text>You can skim<jupyter_code>profile = get_ipython().profile_dir.location
profile
ls $profile<jupyter_output><empty_output><jupyter_text>Let's peek at our config file<jupyter_code>pycat $profile/ipython_config.py<jupyter_output><empty_output><jupyter_text>The %config magic The `%config` magic lets you do some configuration at runtime, rather than in configuration files.<jupyter_code>%matplotlib inline<jupyter_output><empty_output><jupyter_text>`%config` with no arguments will show you what configurable objects exist:<jupyter_code>%config<jupyter_output><empty_output><jupyter_text>And `%config Class` will show you the config for that class:<jupyter_code>%config InlineBackend<jupyter_output><empty_output><jupyter_text>Most importantly, the `%config` magic can be used to change the value of a configurable attribute at runtime. Here we tell the inline matplotlib backend to use SVG instead of the default PNG<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,10,1000)
y = np.sin(x)
plt.plot(x,y)
%config InlineBackend.figure_format = 'svg'
plt.plot(x,y)<jupyter_output><empty_output><jupyter_text>Startup Files Startup files are simple Python or IPython scriptsthat are run whenever you start IPython.These are a useful way to do super common imports,or for building database connections to load on startup of a non-default profile.We can use a startup file to ensure that our `%tic/toc` magics are always defined,every time we start IPython.<jupyter_code>!ls $profile/startup
!cat $profile/startup/README<jupyter_output><empty_output><jupyter_text>Adding common imports, so we never have to forget them again<jupyter_code>#%%writefile $profile/startup/simpleimports.py
#
#import sys, os, time, re<jupyter_output><empty_output><jupyter_text>**Restart the kernel** and then run the following cells immediately to verify these scripts have been executed:<jupyter_code>#sys<jupyter_output><empty_output><jupyter_text>Extensions<jupyter_code>profile = get_ipython().profile_dir.location
!cat $profile/ipython_config.py | grep InteractiveShellApp.extensions
#!echo "c.InteractiveShellApp.extensions = ['mymagics']" >> $profile/ipython_config.py
#!tail $profile/ipython_config.py<jupyter_output><empty_output><jupyter_text>**Restart the kernel** to see the effects:<jupyter_code>#import time
#%tic
#time.sleep(0.1)
#%toc
#%nbrun Sample<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08069953645174884, 'fraction_numerical': 0.0029498525073746312, 'mean_word_length': 6.964765100671141, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '33594', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1418, 'n_words': 494, 'path': '001-Jupyter/001-Tutorials/003-IPython-in-Depth/exercises/Customization/Configuration.ipynb', 'repo_name': 'willirath/jupyter-jsc-notebooks', 'size': '4746'}