nomic-ai/nomic

List projects under my account

YasmineMh opened this issue · 2 comments

Hey, is there a method to list all projects under my Nomic account?
Thanks!

Unless I'm completely failing to find it, there is not--but there should be! We'll try to get something in the next release--I'll start off submitting the following function, which you can use in the meantime if it helps.

from nomic.project import AtlasClass
import requests

def list_projects(organization_id=None):
    """
    Lists all projects in an organization.

    If called without an organization id, it will list all projects in the
    current user's main organization.
    """
    c = AtlasClass()
    if organization_id is None:
        organization = c._get_current_users_main_organization()
        if organization is None:
            raise ValueError(
                "No organization id provided and no main organization found."
            )
        organization_id = organization['organization_id']
    response = requests.get(
        c.atlas_api_path + f"/v1/organization/{organization_id}",
        headers=c.header
    )
    proj_info = response.json()['projects']
    return [
        {'name': p['project_name'],
            'id': p['id'],
            'created_timestamp': p['created_timestamp']}
        for p in proj_info
    ]

Thank you @bmschmidt ! it's working.