diff --git a/nomic/atlas.py b/nomic/atlas.py index fa922327..b60e098b 100644 --- a/nomic/atlas.py +++ b/nomic/atlas.py @@ -16,6 +16,35 @@ from .settings import * from .utils import b64int, get_random_name, arrow_iterator +from .project import AtlasClass +import requests + +def list_projects(organization_id=None): + """ + Lists all projects in an Atlas 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 + ] def map_embeddings( embeddings: np.array, diff --git a/nomic/tests/test_atlas_client.py b/nomic/tests/test_atlas_client.py index 9cb1fa71..5176daf3 100644 --- a/nomic/tests/test_atlas_client.py +++ b/nomic/tests/test_atlas_client.py @@ -468,3 +468,14 @@ def test_map_text_iterator(): map = project.get_map(name='UNITTEST_pandas_text') assert project.total_datums == 50 project.delete() + + +def test_list_projects(): + # Create a project if none exists + proj = AtlasProject(name='existence', modality='text', unique_id_field='id', reset_project_if_exists=False) + projects = atlas.list_projects() + assert len(projects) > 0 + assert isinstance(projects[0], dict) + assert 'name' in projects[0] + assert 'existence' in set([p['name'] for p in projects]) + proj.delete() \ No newline at end of file diff --git a/nomic/utils.py b/nomic/utils.py index c466853c..bb2ff2a7 100644 --- a/nomic/utils.py +++ b/nomic/utils.py @@ -3,7 +3,6 @@ import sys import pyarrow as pa from uuid import UUID - from wonderwords import RandomWord