Skip to content

Projects

PyroProject dataclass

Source code in pyro_dash_py/project.py
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
@dataclass
class PyroProject:
    id: str
    name: str
    created_at: str
    is_active: str
    _resource: Optional[PyroProjectResource]

    @classmethod
    def from_dict(cls, d: dict) -> "PyroProject":
        return PyroProject(
            d["id"],
            d["name"],
            d["created_at"],
            d["is_active"],
            d["_resource"],
        )

    @require_resource
    def add_job(self, job_id: str):
        """
        # Add a job to a project

        ## Example
        ```python
        pyro = PyroDash(...)
        project = pyro.projects.create('test project')
        job_id = "j_r62X.."
        job = project.add_job(job_id)
        ```
        """
        assert self._resource is not None
        return self._resource.add_job(self.id, job_id)

    @require_resource
    def delete(self):
        """
        # Delete a project

        Deleting a project will also delete any jobs and data
        associated with it. Tread carefully.

        ## Example
        ```python
        pyro = PyroDash(...)
        project = pyro.projects.find_by_name("my cringe project")
        project.delete()
        ```
        """
        assert self._resource is not None
        return self._resource.delete(self.id)

    @require_resource
    def duplicate_job(self, job_id: str):
        """
        # Duplicate a job in a project

        ## Example
        ```python
        pyro = PyroDash(...)
        project = pyro.projects.find_by_name("my project")
        job_id = "j_r62X.."
        duped_job = project.duplicate_job(job_id)
        ```
        """
        assert self._resource is not None
        return self._resource.duplicate_job(self.id, job_id)

    @require_resource
    def list_jobs(self):
        """
        # Retrieve all jobs in a project

        This function will return ALL jobs in a project,
        those that are directly associated with a project
        and those that are associated with a project
        through a job group.

        ## Example
        ```python
        pyro = PyroDash(...)
        project = pyro.projects.filter("my project")
        jobs = project.list_jobs()
        ```
        """
        assert self._resource is not None
        return self._resource.list_jobs(self.id)

    @require_resource
    def create_job(self, job: Union[PyroJob, dict]):
        """
        # Creates a new job in this project

        Creates a job and handles automatically adding it to a project.

        You can specify either a `PyroJob` or a `dict` as the `job` parameter.
        The system will automatically use the fields in this object to create
        an entirely new job in this project.

        When you specify a `PyroJob` a new job is created that is simply "modelled"
        after that job i.e. using a set of its properties.

        ## Args:
            id (str): project id
            job (Union[PyroJob | dict]): the properties to use when creating the job

        ## Example
        ```python
        pyro = PyroDash(...)
        project = pyro.projects.get("p_2VF7h")
        new_job = project.create_job({"type": "fsim", "name": "my fsim job"})
        assert new_job.name == "my fsim job"
        ```
        """
        assert self._resource is not None
        return self._resource.create_job(self.id, job)

    @require_resource
    def add_job_group(self, job_group_id: str):
        """
        # Add job group to a project

        ## Example
        ```python
        pyro = PyroDash(...)
        project = pyro.projects.get("p_2VF7h")
        job_group = project.add_job_group("jg_la043")
        ```
        """
        assert self._resource is not None
        return self._resource.add_job_group(self.id, job_group_id)

    @require_resource
    def list_job_groups(self):
        """
        # Retrieves job groups in a project

        ## Example
        ```python
        pyro = PyroDash(...)
        project = pyro.projects.get("p_2VF7h")
        job_groups = project.list_job_groups()
        ```
        """
        assert self._resource is not None
        return self._resource.list_job_groups(self.id)

    @require_resource
    def list_ungrouped_jobs(self):
        """
        # Retrieves ungrouped jobs in a project

        ## Example
        ```python
        jobs = project.list_ungrouped_jobs()
        ```
        """
        assert self._resource is not None
        return self._resource.list_ungrouped_jobs(self.id)

add_job(job_id)

Add a job to a project

Example
pyro = PyroDash(...)
project = pyro.projects.create('test project')
job_id = "j_r62X.."
job = project.add_job(job_id)
Source code in pyro_dash_py/project.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
@require_resource
def add_job(self, job_id: str):
    """
    # Add a job to a project

    ## Example
    ```python
    pyro = PyroDash(...)
    project = pyro.projects.create('test project')
    job_id = "j_r62X.."
    job = project.add_job(job_id)
    ```
    """
    assert self._resource is not None
    return self._resource.add_job(self.id, job_id)

add_job_group(job_group_id)

Add job group to a project

Example
pyro = PyroDash(...)
project = pyro.projects.get("p_2VF7h")
job_group = project.add_job_group("jg_la043")
Source code in pyro_dash_py/project.py
472
473
474
475
476
477
478
479
480
481
482
483
484
485
@require_resource
def add_job_group(self, job_group_id: str):
    """
    # Add job group to a project

    ## Example
    ```python
    pyro = PyroDash(...)
    project = pyro.projects.get("p_2VF7h")
    job_group = project.add_job_group("jg_la043")
    ```
    """
    assert self._resource is not None
    return self._resource.add_job_group(self.id, job_group_id)

create_job(job)

Creates a new job in this project

Creates a job and handles automatically adding it to a project.

You can specify either a PyroJob or a dict as the job parameter. The system will automatically use the fields in this object to create an entirely new job in this project.

When you specify a PyroJob a new job is created that is simply "modelled" after that job i.e. using a set of its properties.

Args:
id (str): project id
job (Union[PyroJob | dict]): the properties to use when creating the job
Example
pyro = PyroDash(...)
project = pyro.projects.get("p_2VF7h")
new_job = project.create_job({"type": "fsim", "name": "my fsim job"})
assert new_job.name == "my fsim job"
Source code in pyro_dash_py/project.py
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
@require_resource
def create_job(self, job: Union[PyroJob, dict]):
    """
    # Creates a new job in this project

    Creates a job and handles automatically adding it to a project.

    You can specify either a `PyroJob` or a `dict` as the `job` parameter.
    The system will automatically use the fields in this object to create
    an entirely new job in this project.

    When you specify a `PyroJob` a new job is created that is simply "modelled"
    after that job i.e. using a set of its properties.

    ## Args:
        id (str): project id
        job (Union[PyroJob | dict]): the properties to use when creating the job

    ## Example
    ```python
    pyro = PyroDash(...)
    project = pyro.projects.get("p_2VF7h")
    new_job = project.create_job({"type": "fsim", "name": "my fsim job"})
    assert new_job.name == "my fsim job"
    ```
    """
    assert self._resource is not None
    return self._resource.create_job(self.id, job)

delete()

Delete a project

Deleting a project will also delete any jobs and data associated with it. Tread carefully.

Example
pyro = PyroDash(...)
project = pyro.projects.find_by_name("my cringe project")
project.delete()
Source code in pyro_dash_py/project.py
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
@require_resource
def delete(self):
    """
    # Delete a project

    Deleting a project will also delete any jobs and data
    associated with it. Tread carefully.

    ## Example
    ```python
    pyro = PyroDash(...)
    project = pyro.projects.find_by_name("my cringe project")
    project.delete()
    ```
    """
    assert self._resource is not None
    return self._resource.delete(self.id)

duplicate_job(job_id)

Duplicate a job in a project

Example
pyro = PyroDash(...)
project = pyro.projects.find_by_name("my project")
job_id = "j_r62X.."
duped_job = project.duplicate_job(job_id)
Source code in pyro_dash_py/project.py
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
@require_resource
def duplicate_job(self, job_id: str):
    """
    # Duplicate a job in a project

    ## Example
    ```python
    pyro = PyroDash(...)
    project = pyro.projects.find_by_name("my project")
    job_id = "j_r62X.."
    duped_job = project.duplicate_job(job_id)
    ```
    """
    assert self._resource is not None
    return self._resource.duplicate_job(self.id, job_id)

list_job_groups()

Retrieves job groups in a project

Example
pyro = PyroDash(...)
project = pyro.projects.get("p_2VF7h")
job_groups = project.list_job_groups()
Source code in pyro_dash_py/project.py
487
488
489
490
491
492
493
494
495
496
497
498
499
500
@require_resource
def list_job_groups(self):
    """
    # Retrieves job groups in a project

    ## Example
    ```python
    pyro = PyroDash(...)
    project = pyro.projects.get("p_2VF7h")
    job_groups = project.list_job_groups()
    ```
    """
    assert self._resource is not None
    return self._resource.list_job_groups(self.id)

list_jobs()

Retrieve all jobs in a project

This function will return ALL jobs in a project, those that are directly associated with a project and those that are associated with a project through a job group.

Example
pyro = PyroDash(...)
project = pyro.projects.filter("my project")
jobs = project.list_jobs()
Source code in pyro_dash_py/project.py
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
@require_resource
def list_jobs(self):
    """
    # Retrieve all jobs in a project

    This function will return ALL jobs in a project,
    those that are directly associated with a project
    and those that are associated with a project
    through a job group.

    ## Example
    ```python
    pyro = PyroDash(...)
    project = pyro.projects.filter("my project")
    jobs = project.list_jobs()
    ```
    """
    assert self._resource is not None
    return self._resource.list_jobs(self.id)

list_ungrouped_jobs()

Retrieves ungrouped jobs in a project

Example
jobs = project.list_ungrouped_jobs()
Source code in pyro_dash_py/project.py
502
503
504
505
506
507
508
509
510
511
512
513
@require_resource
def list_ungrouped_jobs(self):
    """
    # Retrieves ungrouped jobs in a project

    ## Example
    ```python
    jobs = project.list_ungrouped_jobs()
    ```
    """
    assert self._resource is not None
    return self._resource.list_ungrouped_jobs(self.id)

PyroProjectResource

An interface for projects in the Pyro ecosystem.

Provides an organization mechanism for Pyro jobs and job groups.

Source code in pyro_dash_py/project.py
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
class PyroProjectResource:
    """
    An interface for projects in the Pyro ecosystem.

    Provides an organization mechanism for Pyro jobs and job groups.
    """

    def __init__(self, client: PyroApiClient):
        self.client = client
        self._endpoint = "projects"

    def create(self, name: Optional[str] = None):
        """
        # Create a project

        ## Example
        ```python
        pyro = PyroDash(...)
        project = pyro.projects.create("my pyro project")
        print(project.name)
        print(project.id)
        """
        data = {"name": name}
        raw = self.client.request("POST", self._endpoint, data)
        _dict = {**raw, "_resource": self}
        return PyroProject.from_dict(_dict)

    def get(self, id: str):
        """
        # Retrieve a project by ID

        ## Example
        ```python
        pyro = PyroDash(...)
        id = "p_3QZ12NDKxyokJiwLbNBM7G"
        project = pyro.pyrojects.get(id)
        ```
        """
        url = f"{self._endpoint}/{id}"
        raw = self.client.request("GET", url)
        _dict = {**raw, "_resource": self}
        return PyroProject.from_dict(_dict)

    def filter(self, filters: List[ProjectFilter] = [], page=1, num_per_page=10):
        """
        # Retrieve a list of projects

        The projects returned are filtered and paginated in accordance
        with the params you provide. If no filters are provided,
        then all of the projects are retrieved.

        ## Example
        ```python
        pyro = PyroDash(...)

        # Get all of my projects (returns maximum of 20)
        projects = pyro.projects.filter(num_per_page=20)

        # Get all projects that have wildest in the name (not case sensitive)
        filters = [ProjectFilter("name", "wildest")]
        wildest_projects = pyro.projects.filter(filters)
        ```
        """
        params = {
            "page": page,
            "limit": num_per_page,
            "filters": json.dumps([filter.__dict__ for filter in filters]),
        }
        raw = self.client.request("GET", self._endpoint, params)
        projects: List[PyroProject] = []
        for data in raw["data"]:
            _dict = {**data, "_resource": self}
            project = PyroProject.from_dict(_dict)
            projects.append(project)
        return projects

    def find_by_name(self, name: str):
        """
        # Find a project by name

        This function only expects exactly one match. If more or less
        are found, a `ValueError` will be raised.

        ## Example
        ```python
        pyro = PyroDash(...)
        project = pyro.projects.find_by_name("my project")
        print(project.name)
        >>> "my_project"
        project.list_jobs() # etc
        ```
        """
        projects = self.filter([ProjectFilter("name", name)])
        if len(projects) == 0:
            raise ValueError(f"Cannot find project with name: {name}")
        if len(projects) > 1:
            raise ValueError(f"Name {name} is ambiguous, too many results returned")

        return projects[0]

    def create_job(self, id: str, job: Union[PyroJob, dict]) -> PyroJob:
        """
        # Creates a new job in a project

        Creates a job and handles automatically adding it to a project.

        You can specify either a `PyroJob` or a `dict` as the `job` parameter.
        The system will automatically use the fields in this object to create
        an entirely new job in this project.

        When you specify a `PyroJob` a new job is created that is simply "modelled"
        after that job i.e. using a set of its properties.

        ## Args:
            id (str): project id
            job (Union[PyroJob | dict]): the properties to use when creating the job

        ## Example
        ```python
        pyro = PyroDash(...)
        project_id = "p_2VF7h"
        job = {"type": "fsim", "name": "my fsim job"}
        new_job = pyro.projects.create_job(project_id, job)
        assert new_job.name == "my fsim job"
        ```
        """
        if isinstance(job, PyroJob):
            return self.create_job_from_pyrojob(id, job)
        elif isinstance(job, dict):
            return self.create_job_from_dict(id, job)
        else:
            raise TypeError(
                "source job provided is of unexpected type. cannot create a new job from it."
            )

    def create_job_from_dict(self, id: str, job: dict) -> PyroJob:
        """
        # Create a new job in a project (from a dictionary)

        ## Args:
            id (str): project id
            job (dict): the dictionary to use when creating the job

        ## Example
        ```python
        pyro = PyroDash(...)
        project_id = "p_2VF7h"
        job = {"type": "fsim", "name": "my fsim job"}
        new_job = pyro.projects.create_job_from_dict(project_id, job)
        assert new_job.name == "my fsim job"
        ```
        """
        if job["type"] is None:
            raise ValueError("dict specified does not have a type!")

        job_rsc = PyroJobResource(self.client)
        new_job = job_rsc.create(job["type"])
        new_job.update(
            name=job.get("name", "Unlabeled"), description=job.get("description", "")
        )

        self.add_job(id, new_job.id)

        return job_rsc.get(new_job.id)

    def create_job_from_pyrojob(self, id: str, job: PyroJob) -> PyroJob:
        """
        # Create a new job in a project (from a `PyroJob` object)

        ## Args:
            id (str): project id
            job (dict): the dictionary to use when creating the job

        ## Example
        ```python
        pyro = PyroDash(...)
        project_id = "p_2VF7h"
        job = PyroJob("j_r62X", "fsim", ..)
        new_job = pyro.projects.create_job_from_pyrojob(project_id, job)
        ```
        """
        if job.type is None:
            raise ValueError("job specified does not have a type!")

        job_rsc = PyroJobResource(self.client)
        new_job = job_rsc.create(job.type)  # pyright: ignore
        new_job.update(name=job.name, description=job.description)
        self.add_job(id, new_job.id)
        return job_rsc.get(new_job.id)

    def add_job(self, id: str, job_id: str) -> PyroJob:
        """
        # Add a job to a project

        ## Example
        ```python
        pyro = PyroDash(...)
        project_id = "p_2VF7h.."
        job_id = "j_r62X.."
        job = pyro.projects.add_job(project_id, job_id)
        ```
        """
        url = f"{self._endpoint}/{id}/add_job"
        raw = self.client.request(POST, url, {"job_id": job_id})
        _dict = {**raw, "_resource": PyroJobResource(self.client)}
        return PyroJob.from_dict(_dict)

    def add_job_group(self, id: str, job_group_id: str) -> PyroJobGroup:
        """
        # Add job group to a project

        ## Example
        ```python
        pyro = PyroDash(...)
        project_id = "p_2VF7h.."
        job_group_id = "jg_la043"
        job_group = pyro.projects.add_job_group(project_id, job_group_id)
        ```
        """
        url = f"{self._endpoint}/{id}/add_job_group"
        resp = self.client.request(POST, url, {"job_group_id": job_group_id})
        _dict = {**resp, "_resource": PyroJobGroupResource(self.client)}
        return PyroJobGroup.from_dict(_dict)

    def duplicate_job(self, id: str, job_id: str) -> PyroJob:
        """
        # Duplicate a job in a project

        ## Example
        ```python
        pyro = PyroDash(...)
        project_id = "p_2VF7h.."
        job_id = "j_r62X.."
        duplicate_job = pyro.projects.duplicate_job(project_id, job_id)
        ```
        """
        url = f"{self._endpoint}/{id}/duplicate_job"
        raw = self.client.request(POST, url, {"job_id": job_id})
        _dict = {**raw, "_resource": PyroJobResource(self.client)}
        return PyroJob.from_dict(_dict)

    def delete(self, id: str):
        """
        # Delete a project

        Deleting a project will also delete any jobs and data
        associated with it. Tread carefully.

        ## Example
        ```python
        pyro = PyroDash(...)
        project = pyro.projects.find_by_name("my cringe project")
        pyro.projects.delete(project.id)
        ```
        """
        url = f"{self._endpoint}/{id}"
        raw = self.client.request(DEL, url)
        _dict = {**raw, "_resource": self}
        return PyroProject.from_dict(_dict)

    def list_jobs(self, id: str) -> list[PyroJob]:
        """
        # Retrieves jobs in a project

        This function will return ALL jobs in a project,
        those that are directly associated with a project
        and those that are associated with a project
        through a job group.

        ## Example
        ```python
        pyro = PyroDash(...)
        project_id = "p_2VF7h.."
        jobs = pyro.projects.list_jobs(project_id)
        ```
        """
        jobs = self.list_ungrouped_jobs(id)

        # also fetch any jobs that may be in job groups
        # for this project
        job_groups = self.list_job_groups(id)
        for group in job_groups:
            grouped_jobs = group.list_jobs()
            for grouped_job in grouped_jobs:
                jobs.append(grouped_job)

        return jobs

    def list_job_groups(self, id: str) -> list[PyroJobGroup]:
        """
        # Retrieves job groups in a project

        ## Example
        ```python
        pyro = PyroDash(...)
        project_id = "p_2VF7h.."
        job_groups = pyro.projects.list_job_groups(project_id)
        ```
        """
        job_groups = []
        url = f"{self._endpoint}/{id}/job_groups"
        resp = self.client.request(GET, url)
        for job_group in resp["data"]:
            _dict = {**job_group, "_resource": PyroJobGroupResource(self.client)}
            job_groups.append(PyroJobGroup.from_dict(_dict))

        return job_groups

    def list_ungrouped_jobs(self, id: str) -> list[PyroJob]:
        """
        # Retrieves ungrouped jobs in a project

        ## Example
        ```python
        pyro = PyroDash(...)
        project_id = "p_2VF7h.."
        jobs = pyro.projects.list_ungrouped_jobs(project_id)
        ```
        """
        url = f"{self._endpoint}/{id}/jobs"
        resp = self.client.request(GET, url)
        jobs = []
        for lite_job_data in resp["data"]:
            job_id = lite_job_data["id"]
            url = f"jobs/{job_id}"
            job_resp = self.client.request(GET, url)
            _dict = {**job_resp, "_resource": PyroJobResource(self.client)}
            jobs.append(PyroJob.from_dict(_dict))

        return jobs

add_job(id, job_id)

Add a job to a project

Example
pyro = PyroDash(...)
project_id = "p_2VF7h.."
job_id = "j_r62X.."
job = pyro.projects.add_job(project_id, job_id)
Source code in pyro_dash_py/project.py
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
def add_job(self, id: str, job_id: str) -> PyroJob:
    """
    # Add a job to a project

    ## Example
    ```python
    pyro = PyroDash(...)
    project_id = "p_2VF7h.."
    job_id = "j_r62X.."
    job = pyro.projects.add_job(project_id, job_id)
    ```
    """
    url = f"{self._endpoint}/{id}/add_job"
    raw = self.client.request(POST, url, {"job_id": job_id})
    _dict = {**raw, "_resource": PyroJobResource(self.client)}
    return PyroJob.from_dict(_dict)

add_job_group(id, job_group_id)

Add job group to a project

Example
pyro = PyroDash(...)
project_id = "p_2VF7h.."
job_group_id = "jg_la043"
job_group = pyro.projects.add_job_group(project_id, job_group_id)
Source code in pyro_dash_py/project.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
def add_job_group(self, id: str, job_group_id: str) -> PyroJobGroup:
    """
    # Add job group to a project

    ## Example
    ```python
    pyro = PyroDash(...)
    project_id = "p_2VF7h.."
    job_group_id = "jg_la043"
    job_group = pyro.projects.add_job_group(project_id, job_group_id)
    ```
    """
    url = f"{self._endpoint}/{id}/add_job_group"
    resp = self.client.request(POST, url, {"job_group_id": job_group_id})
    _dict = {**resp, "_resource": PyroJobGroupResource(self.client)}
    return PyroJobGroup.from_dict(_dict)

create(name=None)

Create a project

Example

```python pyro = PyroDash(...) project = pyro.projects.create("my pyro project") print(project.name) print(project.id)

Source code in pyro_dash_py/project.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def create(self, name: Optional[str] = None):
    """
    # Create a project

    ## Example
    ```python
    pyro = PyroDash(...)
    project = pyro.projects.create("my pyro project")
    print(project.name)
    print(project.id)
    """
    data = {"name": name}
    raw = self.client.request("POST", self._endpoint, data)
    _dict = {**raw, "_resource": self}
    return PyroProject.from_dict(_dict)

create_job(id, job)

Creates a new job in a project

Creates a job and handles automatically adding it to a project.

You can specify either a PyroJob or a dict as the job parameter. The system will automatically use the fields in this object to create an entirely new job in this project.

When you specify a PyroJob a new job is created that is simply "modelled" after that job i.e. using a set of its properties.

Args:
id (str): project id
job (Union[PyroJob | dict]): the properties to use when creating the job
Example
pyro = PyroDash(...)
project_id = "p_2VF7h"
job = {"type": "fsim", "name": "my fsim job"}
new_job = pyro.projects.create_job(project_id, job)
assert new_job.name == "my fsim job"
Source code in pyro_dash_py/project.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
def create_job(self, id: str, job: Union[PyroJob, dict]) -> PyroJob:
    """
    # Creates a new job in a project

    Creates a job and handles automatically adding it to a project.

    You can specify either a `PyroJob` or a `dict` as the `job` parameter.
    The system will automatically use the fields in this object to create
    an entirely new job in this project.

    When you specify a `PyroJob` a new job is created that is simply "modelled"
    after that job i.e. using a set of its properties.

    ## Args:
        id (str): project id
        job (Union[PyroJob | dict]): the properties to use when creating the job

    ## Example
    ```python
    pyro = PyroDash(...)
    project_id = "p_2VF7h"
    job = {"type": "fsim", "name": "my fsim job"}
    new_job = pyro.projects.create_job(project_id, job)
    assert new_job.name == "my fsim job"
    ```
    """
    if isinstance(job, PyroJob):
        return self.create_job_from_pyrojob(id, job)
    elif isinstance(job, dict):
        return self.create_job_from_dict(id, job)
    else:
        raise TypeError(
            "source job provided is of unexpected type. cannot create a new job from it."
        )

create_job_from_dict(id, job)

Create a new job in a project (from a dictionary)

Args:
id (str): project id
job (dict): the dictionary to use when creating the job
Example
pyro = PyroDash(...)
project_id = "p_2VF7h"
job = {"type": "fsim", "name": "my fsim job"}
new_job = pyro.projects.create_job_from_dict(project_id, job)
assert new_job.name == "my fsim job"
Source code in pyro_dash_py/project.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
def create_job_from_dict(self, id: str, job: dict) -> PyroJob:
    """
    # Create a new job in a project (from a dictionary)

    ## Args:
        id (str): project id
        job (dict): the dictionary to use when creating the job

    ## Example
    ```python
    pyro = PyroDash(...)
    project_id = "p_2VF7h"
    job = {"type": "fsim", "name": "my fsim job"}
    new_job = pyro.projects.create_job_from_dict(project_id, job)
    assert new_job.name == "my fsim job"
    ```
    """
    if job["type"] is None:
        raise ValueError("dict specified does not have a type!")

    job_rsc = PyroJobResource(self.client)
    new_job = job_rsc.create(job["type"])
    new_job.update(
        name=job.get("name", "Unlabeled"), description=job.get("description", "")
    )

    self.add_job(id, new_job.id)

    return job_rsc.get(new_job.id)

create_job_from_pyrojob(id, job)

Create a new job in a project (from a PyroJob object)

Args:
id (str): project id
job (dict): the dictionary to use when creating the job
Example
pyro = PyroDash(...)
project_id = "p_2VF7h"
job = PyroJob("j_r62X", "fsim", ..)
new_job = pyro.projects.create_job_from_pyrojob(project_id, job)
Source code in pyro_dash_py/project.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def create_job_from_pyrojob(self, id: str, job: PyroJob) -> PyroJob:
    """
    # Create a new job in a project (from a `PyroJob` object)

    ## Args:
        id (str): project id
        job (dict): the dictionary to use when creating the job

    ## Example
    ```python
    pyro = PyroDash(...)
    project_id = "p_2VF7h"
    job = PyroJob("j_r62X", "fsim", ..)
    new_job = pyro.projects.create_job_from_pyrojob(project_id, job)
    ```
    """
    if job.type is None:
        raise ValueError("job specified does not have a type!")

    job_rsc = PyroJobResource(self.client)
    new_job = job_rsc.create(job.type)  # pyright: ignore
    new_job.update(name=job.name, description=job.description)
    self.add_job(id, new_job.id)
    return job_rsc.get(new_job.id)

delete(id)

Delete a project

Deleting a project will also delete any jobs and data associated with it. Tread carefully.

Example
pyro = PyroDash(...)
project = pyro.projects.find_by_name("my cringe project")
pyro.projects.delete(project.id)
Source code in pyro_dash_py/project.py
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
def delete(self, id: str):
    """
    # Delete a project

    Deleting a project will also delete any jobs and data
    associated with it. Tread carefully.

    ## Example
    ```python
    pyro = PyroDash(...)
    project = pyro.projects.find_by_name("my cringe project")
    pyro.projects.delete(project.id)
    ```
    """
    url = f"{self._endpoint}/{id}"
    raw = self.client.request(DEL, url)
    _dict = {**raw, "_resource": self}
    return PyroProject.from_dict(_dict)

duplicate_job(id, job_id)

Duplicate a job in a project

Example
pyro = PyroDash(...)
project_id = "p_2VF7h.."
job_id = "j_r62X.."
duplicate_job = pyro.projects.duplicate_job(project_id, job_id)
Source code in pyro_dash_py/project.py
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
def duplicate_job(self, id: str, job_id: str) -> PyroJob:
    """
    # Duplicate a job in a project

    ## Example
    ```python
    pyro = PyroDash(...)
    project_id = "p_2VF7h.."
    job_id = "j_r62X.."
    duplicate_job = pyro.projects.duplicate_job(project_id, job_id)
    ```
    """
    url = f"{self._endpoint}/{id}/duplicate_job"
    raw = self.client.request(POST, url, {"job_id": job_id})
    _dict = {**raw, "_resource": PyroJobResource(self.client)}
    return PyroJob.from_dict(_dict)

filter(filters=[], page=1, num_per_page=10)

Retrieve a list of projects

The projects returned are filtered and paginated in accordance with the params you provide. If no filters are provided, then all of the projects are retrieved.

Example
pyro = PyroDash(...)

# Get all of my projects (returns maximum of 20)
projects = pyro.projects.filter(num_per_page=20)

# Get all projects that have wildest in the name (not case sensitive)
filters = [ProjectFilter("name", "wildest")]
wildest_projects = pyro.projects.filter(filters)
Source code in pyro_dash_py/project.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def filter(self, filters: List[ProjectFilter] = [], page=1, num_per_page=10):
    """
    # Retrieve a list of projects

    The projects returned are filtered and paginated in accordance
    with the params you provide. If no filters are provided,
    then all of the projects are retrieved.

    ## Example
    ```python
    pyro = PyroDash(...)

    # Get all of my projects (returns maximum of 20)
    projects = pyro.projects.filter(num_per_page=20)

    # Get all projects that have wildest in the name (not case sensitive)
    filters = [ProjectFilter("name", "wildest")]
    wildest_projects = pyro.projects.filter(filters)
    ```
    """
    params = {
        "page": page,
        "limit": num_per_page,
        "filters": json.dumps([filter.__dict__ for filter in filters]),
    }
    raw = self.client.request("GET", self._endpoint, params)
    projects: List[PyroProject] = []
    for data in raw["data"]:
        _dict = {**data, "_resource": self}
        project = PyroProject.from_dict(_dict)
        projects.append(project)
    return projects

find_by_name(name)

Find a project by name

This function only expects exactly one match. If more or less are found, a ValueError will be raised.

Example
pyro = PyroDash(...)
project = pyro.projects.find_by_name("my project")
print(project.name)
>>> "my_project"
project.list_jobs() # etc
Source code in pyro_dash_py/project.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def find_by_name(self, name: str):
    """
    # Find a project by name

    This function only expects exactly one match. If more or less
    are found, a `ValueError` will be raised.

    ## Example
    ```python
    pyro = PyroDash(...)
    project = pyro.projects.find_by_name("my project")
    print(project.name)
    >>> "my_project"
    project.list_jobs() # etc
    ```
    """
    projects = self.filter([ProjectFilter("name", name)])
    if len(projects) == 0:
        raise ValueError(f"Cannot find project with name: {name}")
    if len(projects) > 1:
        raise ValueError(f"Name {name} is ambiguous, too many results returned")

    return projects[0]

get(id)

Retrieve a project by ID

Example
pyro = PyroDash(...)
id = "p_3QZ12NDKxyokJiwLbNBM7G"
project = pyro.pyrojects.get(id)
Source code in pyro_dash_py/project.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def get(self, id: str):
    """
    # Retrieve a project by ID

    ## Example
    ```python
    pyro = PyroDash(...)
    id = "p_3QZ12NDKxyokJiwLbNBM7G"
    project = pyro.pyrojects.get(id)
    ```
    """
    url = f"{self._endpoint}/{id}"
    raw = self.client.request("GET", url)
    _dict = {**raw, "_resource": self}
    return PyroProject.from_dict(_dict)

list_job_groups(id)

Retrieves job groups in a project

Example
pyro = PyroDash(...)
project_id = "p_2VF7h.."
job_groups = pyro.projects.list_job_groups(project_id)
Source code in pyro_dash_py/project.py
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
def list_job_groups(self, id: str) -> list[PyroJobGroup]:
    """
    # Retrieves job groups in a project

    ## Example
    ```python
    pyro = PyroDash(...)
    project_id = "p_2VF7h.."
    job_groups = pyro.projects.list_job_groups(project_id)
    ```
    """
    job_groups = []
    url = f"{self._endpoint}/{id}/job_groups"
    resp = self.client.request(GET, url)
    for job_group in resp["data"]:
        _dict = {**job_group, "_resource": PyroJobGroupResource(self.client)}
        job_groups.append(PyroJobGroup.from_dict(_dict))

    return job_groups

list_jobs(id)

Retrieves jobs in a project

This function will return ALL jobs in a project, those that are directly associated with a project and those that are associated with a project through a job group.

Example
pyro = PyroDash(...)
project_id = "p_2VF7h.."
jobs = pyro.projects.list_jobs(project_id)
Source code in pyro_dash_py/project.py
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
def list_jobs(self, id: str) -> list[PyroJob]:
    """
    # Retrieves jobs in a project

    This function will return ALL jobs in a project,
    those that are directly associated with a project
    and those that are associated with a project
    through a job group.

    ## Example
    ```python
    pyro = PyroDash(...)
    project_id = "p_2VF7h.."
    jobs = pyro.projects.list_jobs(project_id)
    ```
    """
    jobs = self.list_ungrouped_jobs(id)

    # also fetch any jobs that may be in job groups
    # for this project
    job_groups = self.list_job_groups(id)
    for group in job_groups:
        grouped_jobs = group.list_jobs()
        for grouped_job in grouped_jobs:
            jobs.append(grouped_job)

    return jobs

list_ungrouped_jobs(id)

Retrieves ungrouped jobs in a project

Example
pyro = PyroDash(...)
project_id = "p_2VF7h.."
jobs = pyro.projects.list_ungrouped_jobs(project_id)
Source code in pyro_dash_py/project.py
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
def list_ungrouped_jobs(self, id: str) -> list[PyroJob]:
    """
    # Retrieves ungrouped jobs in a project

    ## Example
    ```python
    pyro = PyroDash(...)
    project_id = "p_2VF7h.."
    jobs = pyro.projects.list_ungrouped_jobs(project_id)
    ```
    """
    url = f"{self._endpoint}/{id}/jobs"
    resp = self.client.request(GET, url)
    jobs = []
    for lite_job_data in resp["data"]:
        job_id = lite_job_data["id"]
        url = f"jobs/{job_id}"
        job_resp = self.client.request(GET, url)
        _dict = {**job_resp, "_resource": PyroJobResource(self.client)}
        jobs.append(PyroJob.from_dict(_dict))

    return jobs