{ "cells": [ { "cell_type": "markdown", "id": "4a38e2e2", "metadata": {}, "source": [ "# Getting started\n", "This example shows how to connect to Granta MI to access version information and activity reports." ] }, { "cell_type": "markdown", "id": "1a9f12a9", "metadata": {}, "source": [ "## Connect to Granta MI" ] }, { "cell_type": "markdown", "id": "860931a2", "metadata": {}, "source": [ "First, use the ``ansys.grantami.system.Connection`` class to connect to the Granta MI\n", "server. The ``Connection`` class uses a fluent interface to build the connection, which is\n", "always invoked in the following sequence:\n", "\n", "1. Specify your Granta MI Service Layer URL as a parameter to the ``Connection`` class.\n", "2. Specify the authentication method using a ``Connection.with_...()`` method.\n", "3. Use the ``Connection.connect()`` method to finalize the connection.\n", "\n", "This returns a client object, called ``client`` in these examples." ] }, { "cell_type": "code", "execution_count": null, "id": "52244532", "metadata": {}, "outputs": [], "source": [ "from ansys.grantami.system import Connection\n", "\n", "connection = Connection(\"http://my_grantami_server/mi_servicelayer\").with_autologon()\n", "client = connection.connect()" ] }, { "cell_type": "markdown", "id": "044fddc2", "metadata": {}, "source": [ "## Access Granta MI version information\n", "The Granta MI version can be accessed with the ``SystemApiClient.get_granta_mi_version()`` method." ] }, { "cell_type": "code", "execution_count": null, "id": "18cc7191", "metadata": {}, "outputs": [], "source": [ "mi_version = client.get_granta_mi_version()\n", "print(mi_version)" ] }, { "cell_type": "markdown", "id": "60ac8fa9", "metadata": {}, "source": [ "The `.version` property is a tuple, and can be compared with a minimum required version\n", "using the `>` operator." ] }, { "cell_type": "code", "execution_count": null, "id": "68921a9b", "metadata": {}, "outputs": [], "source": [ "minimum_version = (25, 2)\n", "if mi_version.version > minimum_version:\n", " print(\"Granta MI version meets minimum requirements\")\n", "else:\n", " print(\"Granta MI version does not meet minimum requirements\")" ] }, { "cell_type": "markdown", "id": "b640800d", "metadata": {}, "source": [ "## Access activity report\n", "The activity report describes which users have accessed the Granta MI server. This report lists all user activity in\n", "the Granta MI system and includes the following information:\n", "\n", "* The time an activity occurred\n", "* Who performed the activity\n", "* The MI application and database that were used\n", "* Whether this was a read or edit activity\n", "\n", "Use the ``SystemApiClient.get_activity_report()`` method to access the report as an iterator of ``ActivityItem``\n", "objects." ] }, { "cell_type": "code", "execution_count": null, "id": "a2621e8e", "metadata": {}, "outputs": [], "source": [ "items = client.get_activity_report()\n", "item = next(items)\n", "print(item)" ] } ], "metadata": { "jupytext": { "formats": "ipynb,py:light" }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }