title: Jupyter Client Connect to Running Kernel via Python
body: <p>I am trying to programmatically (with Python) interact with my running jupyter kernel as a prototyping experiment.</p>
  
  <p>I have a jupyter notebook running in my browser and I got the connection info from the notebook via the magic command </p>
  
  <pre><code>%connect_info
  {
   "signature_scheme": "hmac-sha256",
   "shell_port": 49545,
   "kernel_name": "",
   "iopub_port": 49546,
   "stdin_port": 49547,
   "hb_port": 49549,
   "control_port": 49548,
   "key": "1a359267-f30d84302c39d352d6ac17c3",
   "transport": "tcp",
   "ip": "127.0.0.1"
  }
  </code></pre>
  
  <p>The <a href="http://jupyter-client.readthedocs.io/en/latest/api/client.html" rel="noreferrer">jupyter_client docs</a> for KernelClient class leads me to believe I can connect with this info and listen to / display code with this object as well as send code to be executed via the kernel I am connected to but, I am not having any luck with what I have been trying such as:</p>
  
  <pre><code>&gt;&gt;&gt; from jupyter_client import KernelClient
  &gt;&gt;&gt; connection = {
    "signature_scheme": "hmac-sha256",
    "shell_port": 49545,
    "kernel_name": "",
    "iopub_port": 49546,
    "stdin_port": 49547,
    "hb_port": 49549,
    "control_port": 49548,
    "key": "1a359267-f30d84302c39d352d6ac17c3",
    "transport": "tcp",
    "ip": "127.0.0.1"
  }
  &gt;&gt;&gt; client = KernelClient(**connection)
  &gt;&gt;&gt; client.history()
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/path/to/envs/jupyter-nb/lib/python3.5/site-packages/jupyter_client/client.py", line 347, in history
  self.shell_channel.send(msg)
    File "/path/to/envs/jupyter-nb/lib/python3.5/site-packages/jupyter_client/client.py", line 143, in shell_channel
  socket, self.session, self.ioloop
  &gt;&gt;&gt; client.start_channels()
    Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/path/to/jupyter-nb/lib/python3.5/site-packages/jupyter_client/client.py", line 101, in start_channels
  self.shell_channel.start()
    File "/path/to/jupyter-nb/lib/python3.5/site-packages/jupyter_client/client.py", line 143, in shell_channel
  socket, self.session, self.ioloop
   TypeError: object() takes no parameters
   &gt;&gt;&gt; client.load_connection_info(connection)
   &gt;&gt;&gt; client.execute('print("Hello World")')
     Traceback (most recent call last):
     File "&lt;stdin&gt;", line 1, in &lt;module&gt;
     File "/path/to/jupyter-nb/lib/python3.5/site-packages/jupyter_client/client.py", line 254, in execute
  self.shell_channel.send(msg)
     File "/path/to/jupyter-nb/lib/python3.5/site-packages/jupyter_client/client.py", line 143, in shell_channel
  socket, self.session, self.ioloop
     TypeError: object() takes no parameters
  </code></pre>
  
  <p>EDIT: Adding this section for clarity given @Sam H. suggestion I did this but it did not work</p>
  
  <pre><code>&gt;&gt;&gt; from jupyter_client import KernelClient
  &gt;&gt;&gt; kc = KernelClient()
  &gt;&gt;&gt; kc.load_connection_info(connection)
  &gt;&gt;&gt; kc.start_channels()
    Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/path/to/jupyter-nb/lib/python3.5/site-packages/jupyter_client/client.py", line 101, in start_channels
    self.shell_channel.start()
    File "/path/to/jupyter-nb/lib/python3.5/site-packages/jupyter_client/client.py", line 143, in shell_channel
    socket, self.session, self.ioloop
    TypeError: object() takes no parameters
  </code></pre>