Lattix Python API

Lattix Python API#

The Lattix Python API is located in the directory <Lattix Install>/python_api

Currently Python 3.12 is required.

Note

For the complete auto-generated API reference documentation, see python_api_reference

There are multiple ways to make the directory accessible to Python. One way is to set the environment variable PYTHONPATH to include the directory <Lattix Install>/python_api.

import pyliblattix

# initialized the lattix api
lattix_api = pyliblattix.acquire_lattix_api()

# load a project
project_model = lattix_api.open_lattix_project("/path/to/myfile.ldz")

# get the root partition
root = project_model.root_partition
print(root.name)

You can use VS Code to get api code completion, by typing “.” after an object:

vscode-python-code-assist

# Create a named tag
color = project_model.color_from_str("green")
tag = project_model.create_or_find_tag("mytag", color)
print(f"Successfully created tag: {tag.name}")

# Search for text "list" in partitions with atoms
search_builder = project_model.new_search_criteria_builder()
criteria = search_builder.partitions_with_atoms().text("list").build()
project_model.set_tag_criteria(tag, criteria)

# Get all the tagged partitions
tagged_parts = project_model.get_tagged_partitions(tag)
part_iterator = tagged_parts.iterator()
while part_iterator.has_next():
      part = part_iterator.next()
      print(f"Tagged part: {part.name}")
# Get all the tags in the project
tags = project_model.all_tags
tag_iterator = tags.iterator()
while tag_iterator.has_next():
      tag = tag_iterator.next()
      print(f"Tag: {tag.name}")
# Create a partition collection that contains the root partition
parts = project_model.new_partition_set()
parts.add(project_model.root_partition)

# Get all the edges in the partition collection
edges = project_model.get_uses_edges2(parts)

edge_iterator = edges.iterator()
while edge_iterator.has_next():
      edge = edge_iterator.next()
      target_atom = project_model.get_target_atom_for2(edge)
      print(f"Edge: {edge.source_atom.name} -> {target_atom.name}")
# Get all the work items in the project
work_items = project_model.work_items
workitem_iterator = work_items.iterator()
while workitem_iterator.has_next():
      workitem = workitem_iterator.next()
      print(f"Workitem: {workitem.name}")
parts = project_model.new_partition_set()
parts.add(project_model.root_partition)

# Get all the atoms contains in the partition collection
atoms = project_model.get_all_atoms(parts)
atom_iterator = atoms.iterator()
while atom_iterator.has_next():
      atom = atom_iterator.next()
      print(f"  Atom {atom.name}")
part_set = project_model.new_partition_set()
part_set.add(project_model.root_partition)

# Get all the partitions that represent atoms that are children of the partition collection
part_iterator = project_model.get_atom_partition_iterator(part_set)
while part_iterator.has_next():
    part = part_iterator.next()
    parts_set.add(part)
    print(f"  Part {part.name}")
# Iterate over atoms

tagged_parts = project_model.get_tagged_partitions(tag)
atom_set = project_model.partitions_to_atoms(parts)
atom_iterator = atom_set.iterator()

while atom_iterator.has_next():
      atom = atom_iterator.next()
      print(f"  Atom {atom.name}")
# Find edges between partition collections
edges = project_model.get_edges_between(part_set, tagged_parts)
edge_iterator = edges.iterator()
while edge_iterator.has_next():
      edge = edge_iterator.next()
      target_atom = project_model.get_target_atom_for2(edge)
      print(f"Edge: {edge.source_atom.name} -> {target_atom.name}")