Skip to content

Idiomatic Python API #56

Closed
Closed

Description

@rgov

Has any thought been given to developing an idiomatic Python API for Fast DDS? The API requires a coding style that is fairly unnatural in Python.

Some examples:

Accessing instance variables on objects:

# not idiomatic
data.message()
self.topic_data_type.getName()

# idiomatic
data.message
self.topic_data_type.name

Setting instance variables on objects:

# not idiomatic
data.message("Hello World")
self.topic_data_type.setName("HelloWorld")  # p.s., why does this one use "set" and other doesn't?


# idiomatic
data.message = "Hello World"
self.topic_data_type.name = "HelloWorld"

Passing objects by reference to have them initialized:

# not idiomatic
info = fastdds.SampleInfo()
data = HelloWorld.HelloWorld()
reader.take_next_sample(data, info)

# idiomatic
data, info = reader.take_next_sample()


# not idiomatic
self.subscriber_qos = fastdds.SubscriberQos()
self.participant.get_default_subscriber_qos(self.subscriber_qos)

# idiomatic, kind of?
self.subscriber_qos = self.participant.create_subscriber_qos()
self.subscriber_qos = fastdds.SubscriberQos.create_from(self.participant)

Manual management of resources:

# not idiomatic
factory = fastdds.DomainParticipantFactory.get_instance()
self.participant.delete_contained_entities()
factory.delete_participant(self.participant)

# idiomatic, often happens implicitly
del self.participant

Activity

  1. rgov commented on Aug 4, 2023

    @rgov
    Author

    Presumably this is mostly a consequence of using SWIG to generate the Python bindings.

    SWIG does have %attribute for wrapping setters and getters in an idiomatic way.

    I've also heard decent things about pybind11. This example shows how to handle mapping Python object properties to C++ setters and getters like getName() and setName()

  2. JLBuenoLopez commented on Sep 12, 2023

    @JLBuenoLopez
    Contributor

    Thanks @rgov for your contribution

    I have labeled this as an enhancement and I am moving the ticket to the Ideas discussion forum. For the moment the Python API will remain as it is.

  3. locked and limited conversation to collaborators on Sep 12, 2023
  4. converted this issue into a discussion #62 on Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions