{"id":21734657,"url":"https://github.com/ansys/api-eigen-example","last_synced_at":"2025-04-13T01:36:44.335Z","repository":{"id":37361410,"uuid":"477641069","full_name":"ansys/api-eigen-example","owner":"ansys","description":"Ansys API example repository for demonstrating the use of REST and gRPC in different SW languages (Python, C++...)","archived":false,"fork":false,"pushed_at":"2025-04-12T03:19:08.000Z","size":4369,"stargazers_count":8,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T01:36:27.292Z","etag":null,"topics":["api","cpp","grpc","python","rest"],"latest_commit_sha":null,"homepage":"https://apieigen.docs.ansys.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ansys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-04T09:55:56.000Z","updated_at":"2025-04-09T07:19:35.000Z","dependencies_parsed_at":"2023-10-15T04:32:43.449Z","dependency_job_id":"efa40236-ca25-4cbe-bbf3-9b1b4b8bd3a6","html_url":"https://github.com/ansys/api-eigen-example","commit_stats":null,"previous_names":["ansys/api-eigen-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansys%2Fapi-eigen-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansys%2Fapi-eigen-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansys%2Fapi-eigen-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansys%2Fapi-eigen-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ansys","download_url":"https://codeload.github.com/ansys/api-eigen-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654031,"owners_count":21140236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","cpp","grpc","python","rest"],"created_at":"2024-11-26T05:09:58.894Z","updated_at":"2025-04-13T01:36:44.280Z","avatar_url":"https://github.com/ansys.png","language":"Python","readme":"# API Eigen Example project\n\n## IMPORTANT\n\nThis repository is **for demonstration purposes only**. It is not intended to expose the\nEigen library as a service, nor is it expected to be used as a product. This demo is for demonstrating\nthe REST and gRPC communication protocols via client-server interactions, with interactive examples,\ndocumentation, and resources.\n\nThe repository provides a baseline (or guidelines) for future projects that have to deal with API protocols such as REST and gRPC, in different languages,\nwith a higher level of complexity than a simple \"Hello World\" project.\n\n\n## Table of contents\n\n\u003c!--ts--\u003e\n   * [Introduction](#introduction)\n   * [Documentation](#documentation)\n   * [Getting Started with the Python Packages](#getting-started-with-the-python-packages)\n      * [Installation](#installation)\n      * [Starting to use it](#starting-to-use-it)\n   * [Getting Started with the C++ Packages](#getting-started-with-the-c-packages)\n      * [Installing the C++ REST Server](#installing-the-c-rest-server)\n      * [Installing the C++ REST Client](#installing-the-c-rest-client)\n      * [Installing the C++ gRPC Server](#installing-the-c-grpc-server)\n      * [Installing the C++ gRPC Client](#installing-the-c-grpc-client)\n\u003c!--te--\u003e\n\n## Introduction\n\nThe API Eigen Example package is a simple packing for showing PyAnsys\nusers and developers the differences between the API REST communication protocol\nand the gRPC communication protocol that is used extensively in PyAnsys libraries.\n\nThe main goal of this demo is to expose the [Eigen library](https://eigen.tuxfamily.org/index.php?title=Main_Page)\nto end users via a client-server interaction that can be implemented using API REST\nor gRPC communication protocols.\n\nThe server exposes certain functionalities of the Eigen library, such as adding and\nmultiplying ``Eigen::VectorXd`` and ``Eigen::MatrixXd`` objects. The computational operations are\nperformed in the Eigen library installed within the server, and results are returned to the\nend user (or client). Thus, it is not necessary for the client to have the Eigen library installed.\n\nThe client is intended to aid end users because it provides them with tools for\ncommunicating with the server without needing to know the specifics of the protocol implemented.\nHowever, you can use CURL commands to interact directly with the server via API REST communication.\n\n## Documentation\n\nAn automatically generated version of the project's documentation is published every night at [link](https://apieigen.docs.ansys.com/).\nYou can search the documentation for more specific information on the project itself.\n\n## Getting started with the Python packages\n\nTo use the API Eigen Example Python project in its Python version, you do not need any specific requirements or\nadditional software, apart from the ones that are installed via the requirements ``--all-files``\nand a CMake version of the Eigen library.\n\n### Installation\n\nFirst install the Eigen library (and CMake if it is not present). For Ubuntu distributions, it is as easy as running:\n\n```\n    sudo apt install cmake libeigen3-dev\n```\n\nTo install a local version of the API Eigen Example project, clone the [repository](https://github.com/ansys/api-eigen-example) through\nthe Ansys GitHub Enterprise account:\n\n```\n    git clone https://github.com/ansys/api-eigen-example.git\n```\n\n**Note**: \nOther Ansys Python packages are available through the Ansys GitHub Enterprise account or\nthrough [PyPI](https://www.pypi.org). \n\nIf you want to use Python versions of the API Eigen Example project, install the demo-eigen-wrapper, which is a wrapper to the Eigen library that uses pybind11:\n\n```\n    pip install -r requirements/requirements_eigen_wrapper.txt ./src/ansys/eigen/cpp/eigen-wrapper\n```\n\nFinally, install the project with:\n\n```\n    pip install -r requirements/requirements_build.txt .\n```\n\n### Starting to use it\n\nOnce the API Eigen Example project has been installed, start to make use of the Python\npackages by importing them:\n\n```\n    \u003e\u003e\u003e import ansys.eigen.python.rest.server as rest_server\n    \u003e\u003e\u003e import ansys.eigen.python.rest.client as rest_client\n    \u003e\u003e\u003e client = rest_client.DemoRESTClient(\"127.0.0.1\", 5000)\n    \u003e\u003e\u003e client.get_connection_details()\n```\n\n## Getting Started with the C++ packages\nTo use the API Eigen Example C++ projects, the installation process is a bit more cumbersome.\nFirst install the packaged library ``cmake``:\n\n```bash\n    sudo apt install cmake\n```\n\nDepending on the C++ project, dependencies vary. Go to your sections of interest from those that follow.\n\n### Installing the C++ REST server\n\nInstalling the C++ REST server manually is a simple process. Run the following commands from\nthe root of the repository.\n\n```bash\n    pip install -r requirements/requirements_build.txt .\n    cd src/ansys/eigen/cpp/rest/server/build/\n    conan install .. \u0026\u0026 cmake .. \u0026\u0026 cmake --build . \u0026\u0026 sudo make install\n```\n\nOnce dependencies are installed, you can use the C++ REST server. Start writing your own C++ ``main.cpp`` file and\ninclude the project header files as follows:\n\n```cpp\n    #include \u003capieigen/rest/RestServer.hpp\u003e\n\n    int main() {\n       // Let us instantiate our server\n       ansys::rest::server::RestServer server{};\n\n       // Start serving!\n       server.serve();\n    }\n```\n\nFor compiling, link the library with:\n\n```bash\n    g++ -o myServer main.cpp -lapi_eigen_example_rest_server\n```\n\nYou can run your server with:\n\n```bash\n    ./myServer\n```\n\n### Installing the C++ REST client\n\nInstalling the C++ REST client manually is a bit more complex. You must install some\ndevelopment libraries and compile in place some additional external libraries.\n\nFirst, install a ``dev`` version of ``libcurl``. Using the Ubuntu package manager ``apt``, you can run:\n\n```bash\n    sudo apt install libcurl4-openssl-dev\n```\n\nOnce  ``libcurl-dev`` is installed, you must compile some external projects. These external projects have been frozen at a given version\nwithin this repository. You can find them in the ``external`` folder. To install them, run these commands:\n\n```bash\n    sudo apt update \u0026\u0026 sudo apt install libcurl4-openssl-dev \u0026\u0026 cd external/restclient-cpp-v0.5.2 \u0026\u0026 ./autogen.sh \u0026\u0026 ./configure \u0026\u0026 sudo make install \u0026\u0026 cd -\n    sudo apt update \u0026\u0026 cd external/jsoncpp-v1.9.5/build \u0026\u0026 cmake -DCMAKE_INSTALL_INCLUDEDIR=include/jsoncpp .. \u0026\u0026 sudo make install \u0026\u0026 cd - \n```\n\nOnce dependencies are installed, you can build and install the client library with:\n\n```bash\n    cd src/ansys/eigen/cpp/rest/client/build/ \u0026\u0026 cmake .. \u0026\u0026 cmake --build . \u0026\u0026 sudo make install \u0026\u0026 cd -\n```\n\nYou can now use the REST C++ client library. Start writing your own C++ ``client.cpp`` file and\ninclude the project header files as follows:\n\n```cpp\n\n   #include \u003cvector\u003e\n   #include \u003capieigen/rest/EigenClient.hpp\u003e\n\n   int main(int argc, char const *argv[]) {\n       // ------------------------------------------------------------------------\n       // Deploying the client\n       // ------------------------------------------------------------------------\n       // Instantiate an EigenClient\n       auto client = ansys::rest::client::EigenClient(\"http://0.0.0.0:18080\");\n\n       // ------------------------------------------------------------------------\n       // REQUESTING GREETING - A.K.A \"Hello World\"\n       // ------------------------------------------------------------------------\n       // Let us request a greeting!\n       client.request_greeting();\n\n       // Exit successfully\n       return 0;\n   }\n```\n\nFor compiling, link the library as follows:\n\n```bash\n    g++ -o myClientApp client.cpp -lapi_eigen_example_rest_client\n```\n\nYou can run your client app with:\n\n```bash\n    ./myClientApp\n```\n\n### Installing the C++ gRPC Server\n\nInstalling the C++ gRPC server manually is a simple process. To use the [conan](https://conan.io/) package manager\nto install dependencies, run the following command lines from the root of the repository:\n\n```bash\n    cd src/ansys/eigen/cpp/grpc/server/\n    make compile \u0026\u0026 make install \u0026\u0026 ./deploy_dependencies.sh\n```\n\nYou might need to run the previous ``install`` and ``deploy`` commands with root privileges.\n\nOnce dependencies are installed, you can use the C++ gRPC server. Start writing your own C++ ``main.cpp`` file and\ninclude the project header files as follows:\n\n```cpp\n    #include \u003capieigen/grpc/GRPCServer.hpp\u003e\n\n    int main() {\n       // Let us instantiate our server\n       ansys::grpc::server::GRPCServer server{};\n\n       // Start serving!\n       server.serve();\n    }\n```\n\nFor compiling, link the library as follows:\n\n```bash\n    g++ -o myServer main.cpp -lapi_eigen_example_grpc_server\n```\n\nYou can run your server with:\n\n```bash\n    ./myServer\n```\n\n### Installing the C++ gRPC Client\n\nInstalling the C++ gRPC client manually is a simple process. To use the [conan](https://conan.io/) package manager\nto install its dependencies, run the following commands from the root of the repository:\n\n```bash\n    cd src/ansys/eigen/cpp/grpc/client/\n    make compile \u0026\u0026 make install \u0026\u0026 ./deploy_dependencies.sh\n```\n\nYou might need to run the previous ``install`` and ``deploy`` commands with root privileges.\n\nOnce dependencies are installed, you can use the C++ gRPC client. Start writing your own C++ ``main.cpp`` file and\ninclude the project header files as follows:\n\n```cpp\n    #include \u003cvector\u003e\n    #include \u003capieigen/grpc/GRPCClient.hpp\u003e\n\n    int main() {\n        // ------------------------------------------------------------------------\n        // Deploying the client\n        // ------------------------------------------------------------------------\n        // Instantiate a GRPCClient\n        ansys::grpc::client::GRPCClient client{\"0.0.0.0\", 50000};\n\n        // ------------------------------------------------------------------------\n        // REQUESTING GREETING - A.K.A \"Hello World\"\n        // ------------------------------------------------------------------------\n        // Let us request a greeting!\n        client.request_greeting(\"Michael\");\n\n        // ------------------------------------------------------------------------\n        // Performing vector operations\n        // ------------------------------------------------------------------------\n        // Let us create some reference vectors\n        std::vector\u003cdouble\u003e vec1{1.0, 2.0, 3.0, 50.0};\n        std::vector\u003cdouble\u003e vec2{4.0, 5.0, 8.0, 10.0};\n\n        // Let us add them\n        auto result = client.add_vectors(vec1, vec2);\n\n        // Exit successfully\n        return 0;\n    }\n```\n\nFor compiling, link the library as follows:\n\n```bash\n    g++ -o myClientApp main.cpp -lapi_eigen_example_grpc_client\n```\n\nYou can run your client with:\n\n```bash\n    ./myClientApp\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fansys%2Fapi-eigen-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fansys%2Fapi-eigen-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fansys%2Fapi-eigen-example/lists"}