Manage projects#

This example shows how to manage SysML v2 projects on a SAM server using the SysML2ProjectManager class. It explains how to perform these tasks:

  • List all existing projects.

  • Create a new project.

  • Update a project name and description.

  • Delete a project.

Note

For more details on each operation, see the user guide page Manage projects.

Prerequisites#

Ensure that you meet these prerequisites:

  • A running SAM server instance.

  • A valid organization ID and token.

Python example#

Project management: create, list, update, and delete projects#
 1# Copyright (C) 2024 - 2026 ANSYS, Inc. and/or its affiliates.
 2# SPDX-License-Identifier: MIT
 3#
 4#
 5# Permission is hereby granted, free of charge, to any person obtaining a copy
 6# of this software and associated documentation files (the "Software"), to deal
 7# in the Software without restriction, including without limitation the rights
 8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
22
23"""Example showing project management: create, list, update, and delete projects."""
24
25import requests
26from urllib3.exceptions import InsecureRequestWarning
27
28from ansys.sam.sysml2 import AnsysSysML2APIConnector, SysML2ProjectManager
29
30requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
31
32# Create your connector for the SAM Server
33connector = AnsysSysML2APIConnector(
34    server_url="<SAM Server URL>",  # Your SAM server base URL
35    organization_id="<Orga ID>",  # The organization ID
36    token="<Token>",  # Your authorization token
37    use_ssl=False,  # If the server hasn't a valid SSL
38)
39
40project_manager = SysML2ProjectManager(connector=connector)
41
42# --- List all existing projects ---
43projects = project_manager.get_projects()
44print(f"Found {len(projects)} project(s):")
45for p in projects:
46    print(f"  - {p['name']} (id: {p['@id']})")
47
48# --- Create a new project ---
49my_project = project_manager.create_scripting_project(
50    name="My New Project",
51    description="A project created via PySAM SysML2",
52)
53project_id = my_project.get_id()
54print(f"\nCreated project: {my_project.get_name()} (id: {project_id})")
55
56# --- Update the project ---
57updated = project_manager.update_project(
58    project_id=project_id,
59    name="My Renamed Project",
60    description="Updated description",
61)
62print(f"\nUpdated project: {updated['name']} - {updated['description']}")
63
64# --- Delete the project ---
65deleted = project_manager.delete_project(project_id=project_id)
66print(f"\nDeleted project with id: {deleted['@id']}")

Note

  • Replace placeholder values with your actual SAM configuration.

  • Deleting a project is irreversible. All data associated with the project is permanently removed.