# Not sure how to implement a python class in PyCall

**URL:** https://discourse.julialang.org/t/not-sure-how-to-implement-a-python-class-in-pycall/73751
**Category:** General Usage
**Tags:** pycall
**Created:** [December 29, 2021, 12:06pm UTC](https://discourse.julialang.org/t/not-sure-how-to-implement-a-python-class-in-pycall/73751 "2021-12-29T12:06:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)
#### Post date: [December 29, 2021, 12:06pm UTC](https://discourse.julialang.org/t/not-sure-how-to-implement-a-python-class-in-pycall/73751/1 "2021-12-29T12:06:21Z")

</div>

I am trying to use PyCall to reuse a python script which has this code component. I have avoided using python’s oo class system and so I’m not too sure what is going on.

```julia
from ib_insync import *

ib = IB()

ib.connect('nnn.nnn.n.nnn', 1234, clientId=12)

```

I would like to expose the class IB as ib as in the code segment as in

```julia
ib = IB()

```

I have read through [Pycall docs " defining python classes"](https://github.com/JuliaPy/PyCall.jl) but I’m just winging it here.

```julia
Defining Python Classes
using PyCall
tk = pyimport("Tkinter")

@pydef mutable struct SampleApp <: tk.Tk

```

so would the following julia code achieve the same thing?

```julia
IB = pyimport("ib_insync")

@pydef mutable struct ib <: IB()

ib.connect('nnn.nnn.n.nnn', 1234, clientId=12

```

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [December 29, 2021, 1:55pm UTC](https://discourse.julialang.org/t/not-sure-how-to-implement-a-python-class-in-pycall/73751/2 "2021-12-29T13:55:45Z")

</div>

> [@anon69491625](#):
>
> ```julia
> from ib_insync import *
> 
> ib = IB()
> 
> ib.connect('nnn.nnn.n.nnn', 1234, clientId=12)
> 
> ```

This doesn’t involve defining a new Python class at all, so you could replicate it in PyCall simply with:

```julia
ib_insync = pyimport("ib_insync")
ib = ib_insync.IB()
ib.connect("nnn.nnn.n.nnn", 1234, clientId=12)

```

Are you confusing _defining_ a new class with _instantiating_ an existing class?

---

<div class="post-metadata">

### Author: ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)
#### Post date: [December 29, 2021, 2:11pm UTC](https://discourse.julialang.org/t/not-sure-how-to-implement-a-python-class-in-pycall/73751/3 "2021-12-29T14:11:20Z")

</div>

hi @stevengj  
thank you for taking the time. I had a slight issue initially because I didn’t spot the change from single to double quotes. I “think” it’s working now.

I wish you and yours a VERY happy new year.
