List and Iterate Teams
Use the Management API to filter teams with AND filters, iterate all pages with iter(), count members, and read team memberships.
Teams are collections of users within a project's organization. This recipe shows you how to list teams, walk all pages automatically, count members, and read individual team memberships.
Setup
from optixlog import SDKClient
from optixlog.management import Management
client = SDKClient(
base_url="https://optixlog.leidos.com",
api_key="sk-opt-xxxx",
)
mgmt = Management(client)
project = mgmt.project("proj_grating_7f3a")If you are using the generated OptixClient, access the Management API via the .sdk property:
from optixlog.management import Management
from optixlog_gen import OptixClient
client = OptixClient()
mgmt = Management(client.sdk)
project = mgmt.project("proj_grating_7f3a")Listing teams with filters
project.teams.list() returns the first page of results. Filters are AND-combined:
# Teams in the "engineering" category whose name contains "Photonics".
page = project.teams.list(
name="Photonics",
category="engineering",
include=["counts"],
limit=50,
order_by="name",
order="asc",
)
print(f"Page has {len(page.items)} teams, total={page.total}")
for team in page.items:
print(f" {team.name} — {team.member_count} members")The include=["counts"] flag populates team.member_count. Without it, member_count is None.
Iterating all pages with iter()
Use iter() to walk every team without managing cursor pagination manually:
for team in project.teams.iter(category="engineering", include=["counts"]):
print(f"{team.id}: {team.name} ({team.member_count} members)")iter() makes as many HTTP requests as needed to exhaust all pages, yielding each Team object one at a time.
Counting teams
Use count() when you only need the total, not the items:
total_engineering = project.teams.count(category="engineering")
print(f"Engineering teams: {total_engineering}")count() does not populate team objects — it is a lightweight aggregate call.
Strict and nullable lookups
# Raises NotFoundError if not found.
team = project.teams.get("team-id", include=["counts"])
# Returns None if not found.
maybe_team = project.teams.get_or_none("team-id")
# Raises NotFoundError (0 matches) or MultipleResultsError (>1 match).
exact_team = project.teams.one(name="Photonics Design", category="engineering")
# Returns the first match or None.
first_photonics = project.teams.first(category="engineering")Reading team memberships
Each Team object exposes a memberships collection. List memberships with an optional include=["user"] to embed the full User object:
team = project.teams.get("team-id", include=["counts"])
# List the first page of members.
members_page = team.memberships.list(
include=["user"],
limit=100,
order_by="joined_at",
order="desc",
)
for membership in members_page.items:
user = membership.user
print(
f" {user.name} <{user.email}> — role: {membership.role}, "
f"joined: {membership.joined_at.date()}"
)Iterating all members across all teams
Combine iter() on teams with iter() on memberships to walk every member in the project:
seen_user_ids: set[str] = set()
for team in project.teams.iter(include=["counts"]):
print(f"\nTeam: {team.name}")
for membership in team.memberships.iter(include=["user"]):
uid = membership.user_ref.id
if uid not in seen_user_ids:
seen_user_ids.add(uid)
user = membership.user
label = "(new)" if uid not in seen_user_ids else ""
print(f" {user.name if user else uid} [{membership.role}] {label}")For a flat, deduplicated list of all project members use project.get_all_members() instead — see Project Snapshot Report.
Full example
from optixlog import SDKClient
from optixlog.management import Management
def main() -> None:
client = SDKClient(
base_url="https://optixlog.leidos.com",
api_key="sk-opt-xxxx",
)
mgmt = Management(client)
project = mgmt.project("proj_grating_7f3a")
total = project.teams.count()
print(f"Total teams: {total}")
for team in project.teams.iter(include=["counts"]):
print(f"\n{team.name} ({team.member_count or 0} members)")
for m in team.memberships.iter(include=["user"]):
name = m.user.name if m.user else m.user_ref.id
print(f" - {name} [{m.role}]")
client.close()
if __name__ == "__main__":
main()