# Custom Types in Python Bridge

**URL:** <https://forum.rtmaps.com/t/custom-types-in-python-bridge/60>\
**Category:** User SDK\
**Created:** [April 10, 2024, 3:59pm UTC](https://forum.rtmaps.com/t/custom-types-in-python-bridge/60 "2024-04-10T15:59:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel.Pz](https://forum.rtmaps.com/letter_avatar_proxy/v4/letter/d/5daacb/32.png) [@Daniel.Pz](https://forum.rtmaps.com/u/Daniel.Pz)\
**Post date:** [April 10, 2024, 3:59pm UTC](https://forum.rtmaps.com/t/custom-types-in-python-bridge/60/1 "2024-04-10T15:59:44Z")

</div>

Hello,

Is it possible to use custom types in the python bridge similar to the C++ SDK ?  
I couldn’t find any documentation or sample specific for PythonBridge.  
Could you help me please? Thanks.

Kind regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![gwenael](https://forum.rtmaps.com/user_avatar/forum.rtmaps.com/gwenael/32/3_2.png) [@gwenael](https://forum.rtmaps.com/u/gwenael)\
**Post date:** [April 10, 2024, 4:10pm UTC](https://forum.rtmaps.com/t/custom-types-in-python-bridge/60/2 "2024-04-10T16:10:33Z")

</div>

Hello Daniel,

Yes it is possible to create and read/write custom structure in a python bridge component. Actually there is a sample about that, located in in _“packages\rtmaps\_python\_bridge\samples\Chapter2\_Types\_Creation”_

Here is one of the code samples :

```auto
import rtmaps.types
from ctypes import *
import rtmaps.reading_policy
from rtmaps.base_component import BaseComponent # base class

# This sample uses ctypes : https://docs.python.org/3.7/library/ctypes.html
# This class mirrors a C struct and will be used to read a write from RAW bytes.
class MyCStyleStructType(Structure):
    _fields_ = [('a', c_int),
                ('b', c_int),
                ('c', c_int)]
    _pack_ = 1

# Python class that will be called from RTMaps.
class rtmaps_python(BaseComponent):
    def __init__ (self):
        BaseComponent. __init__ (self) # call base class constructor

    def Dynamic(self):
        # Here "Example" is the name of the custom struct generated
        self.add_output("out", rtmaps.types.CUSTOM_STRUCT, 0, "Example") # Specify output type

    # Birth() will be called once at diagram execution startup
    def Birth(self):
        pass

    # Core() is called every time you have a new input
    def Core(self):
        a = 7
        b = 21
        c = 666
        var = MyCStyleStructType(a, b, c) # Build structure

        bvar = bytes(var)
        self.outputs["out"].write(bvar)

    # Death() will be called once at diagram execution shutdown
    def Death(self):
        pass

```

Just as a reminder, on top of the samples in the installation directory, we also have a [PythonBridge video tutorial on YouTube](https://www.youtube.com/watch?v=puSqEpnDANs&list=PLbTIaZrjkGTNcUPDLWR0TCDUh-BIb1Qgh&index=12).

Hope this helps.  
G.

---

<div class="post-metadata">

**Author:** ![Daniel.Pz](https://forum.rtmaps.com/letter_avatar_proxy/v4/letter/d/5daacb/32.png) [@Daniel.Pz](https://forum.rtmaps.com/u/Daniel.Pz)\
**Post date:** [April 10, 2024, 4:46pm UTC](https://forum.rtmaps.com/t/custom-types-in-python-bridge/60/3 "2024-04-10T16:46:16Z")

</div>

I have found the samples indeed. Thanks a lot !
