Heads Up :
The post you are writing will appear in a public forum. Please ensure all content is appropriate for public consumption. Review the employee guidelines for the community here.
with ncs.maapi.single_read_trans("admin", "python") as t:
path = ncs.maagic.get_node(t, kp)
id = path._parent.id. # depends on your model
You may get a service or action path and navigate from it. In my example, one step up to 'id' leaf.
Python library netaddr can help with the summarization.
https://netaddr.readthedocs.io/en/latest/tutorial_01.html#summarizing-list-of-addresses-and-subnets
https://github.com/drkjam/netaddr