ni-measurement-service


Nameni-measurement-service JSON
Version 0.11.1 PyPI version JSON
download
home_pagehttps://github.com/ni/measurement-services-python/
SummaryMeasurementLink Support for Python
upload_time2022-12-08 23:21:06
maintainer
docs_urlNone
authorNI
requires_python>=3.8,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MeasurementLinkā„¢ Support for Python

- [MeasurementLinkā„¢ Support for Python](#measurementlink--support-for-python)
  - [Introduction](#introduction)
  - [Abbreviations](#abbreviations)
  - [Dependencies](#dependencies)
  - [Examples](#examples)
    - [Setting up the Example Measurements](#setting-up-the-example-measurements)
    - [Executing the Example Measurements](#executing-the-example-measurements)
  - [Developing Measurements: Quick Start](#developing-measurements-quick-start)
    - [Installation](#installation)
    - [Developing a minimal python measurement](#developing-a-minimal-python-measurement)
  - [Steps to run/debug the measurement service](#steps-to-rundebug-the-measurement-service)
  - [Static Registration of Python Measurements](#static-registration-of-python-measurements)
    - [Create a batch file that runs a python measurement](#create-a-batch-file-that-runs-a-python-measurement)
    - [Create Executable for Python Scripts](#create-executable-for-python-scripts)
  - [API References](#api-references)
  - [Appendix: Managing Measurement as Python Package(Project)](#appendix-managing-measurement-as-python-packageproject)
    - [Create and Manage Python Measurement Package using poetry](#create-and-manage-python-measurement-package-using-poetry)
    - [Create and Manage Python Measurement Package using venv](#create-and-manage-python-measurement-package-using-venv)
    - [Create and Manage Python Measurement Package by directly installing `ni-measurement-service` as a system-level package](#create-and-manage-python-measurement-package-by-directly-installing-ni-measurement-service-as-a-system-level-package)

---

## Introduction

MeasurementLink Support for Python (`ni-measurement-service`) is a python framework that enables measurement developers to quickly create python measurements and run them as a service (gRPC).

---

## Dependencies

- Python >= 3.8 [(3.9 recommended)](https://www.python.org/downloads/release/python-3913/)
- [grpcio >= 1.41.1, < 2.x](https://pypi.org/project/grpcio/1.41.1/)
- [protobuf >= 3.20, < 4.x](https://pypi.org/project/protobuf/3.20.0/)
- [pywin32 >= 303 (Only for Windows)](https://pypi.org/project/pywin32/303/)

---

## Examples

The `examples` directory contains the following example projects:  

1. `sample_measurement`: Performs a loopback measurement with various data types.
2. `nidaqmx_analog_input`: Performs a finite analog input measurement with NI-DAQmx.
3. `nidcpower_source_dc_voltage`: Sources and measures a DC voltage with an NI SMU. Provides a Measurement UI
4. `nidcpower_source_dc_voltage_with_labview_ui`: Sources and measures a DC voltage with an NI SMU. Provides a LabVIEW UI
5. `nidmm_measurement`: Performs a measurement using an NI DMM.
6. `nifgen_standard_function`: Generates a standard function waveform using an NI waveform generator.
7. `niscope_acquire_waveform`: Acquires a waveform using an NI oscilloscope.
8. `niswitch_control_relays`: Controls relays using an NI relay driver (e.g. PXI-2567).

### Setting up the Example Measurements

The example measurements shared are *poetry-based* projects. Follow the below steps to  for setting up the example measurement:

1. Install `poetry`. Refer to <https://python-poetry.org/docs/#installation> for information on installing poetry.

2. Open a command prompt, and change the working directory to the directory of the example measurement you want to work with.

    ``` cmd
    cd <path_of_example_measurement>
    REM Example: cd "..\measurement-services-python\examples\dc_measurement"
    ```

3. Run `poetry install`. This command creates/updates the .venv and installs all the dependencies(including `ni-measurement-service` package) needed for the Example into `.venv`

    ``` cmd
    poetry install
    ```
    - If you get a "command not found" error during `poetry install`, make sure that you added the Poetry path to the system path. Refer to [https://python-poetry.org/docs/#installing-with-the-official-installer/Add-poetry-to-your-path](https://python-poetry.org/docs/#installing-with-the-official-installer:~:text=Add%20Poetry%20to%20your%20PATH)
    ![PoetryInstallFail](PoetryInstallFail.png)

### Executing the Example Measurements

1. Start the discovery service if not already started.
2. Use `poetry run` to run the measurement service:

    ``` cmd
    poetry run python measurement.py
    ```

---

## Developing Measurements: Quick Start

This section provides instructions to develop custom measurement services in Python using MeasurementLink Support for Python.

### Installation

Make sure the system has the recommended python version is installed. Install MeasurementLink Support for Python using [pip](https://pip.pypa.io/).

``` cmd
REM Activate the required virtual environment if any.
pip install ni-measurement-service
```

Check if you have installed the expected version of MeasurementLink Support for Python installed by running the below command:

```cmd
pip show ni-measurement-service
```

### Developing a minimal python measurement

1. Install the `ni-measurement-generator` package.

``` cmd
REM Activate the required virtual environment if any.
pip install ni-measurement-generator
```

2. Run the `ni-measurement-generator` tool. Use command line arguments to specify the `display-name` and optionally the `version`, `measurement-type`, and `product-type`.

    1. Running `ni-measurement-generator` without optional arguments:

    `ni-measurement-generator SampleMeasurement`

    'SampleMeasurement' is the display name of your measurement service. Without the optional arguments,
    the other arguments are generated for you based on the display name.

    2. Running `ni-measurement-generator` with optional arguments for `measurement-version`, `ui-file`,
    `service-class`, and `description-url`:

    `ni-measurement-generator SampleMeasurement --measurement-version 0.1.0.0 --ui-file MeasurementUI.measui --service-class SampleMeasurement_Python --description-url https://www.example.com/SampleMeasurement.html`

    3. Running `ni-measurement-generator` with optional argument for `directory-out`

    `ni-measurement-generator SampleMeasurement --directory-out <new_path_for_created_files>`

    If no output directory is specified, the files will
    be placed in a new folder under the current directory
    named after the display name without spaces.

3. To customize the created measurement, provide metadata of the measurement's configuration(input parameters) and outputs(output parameters) in `measurement.py`.
    1. Use the `configuration()` decorator to provide metadata about the configurations.**The order of the configuration decorator must match with the order of the parameters defined in the function signature.**

        ``` python
        @foo_measurement_service.register_measurement
        #Display Names can not contains backslash or front slash.
        @foo_measurement_service.configuration("DisplayNameForInput1", DataType.String, "DefaultValueForInput1")
        @foo_measurement_service.configuration("DisplayNameForInput2", DataType.String, "DefaultValueForInput2")
        def measure(input_1, input_2):
            ''' A simple Measurement method'''
            return ["foo", "bar"]
        ```

    2. Use the `output()` decorator to provide metadata about the output.**The order of the output decorators from top to bottom must match the order of the values of the list returned by the function.**

        ``` python
        @foo_measurement_service.register_measurement
        @foo_measurement_service.configuration("DisplayNameForInput1", nims.DataType.String, "DefaultValueForInput1")
        @foo_measurement_service.configuration("DisplayNameForInput2", nims.DataType.String, "DefaultValueForInput2")
        @foo_measurement_service.output("DisplayNameForOutput1", nims.DataType.String)
        @foo_measurement_service.output("DisplayNameForOutput2", nims.DataType.String)
        def measure(input_1, input_2):
            return ["foo", "bar"]
        ```

4. Run/Debug the created measurement by following the steps discussed in the section ["Steps to run/debug the measurement service".](#steps-to-rundebug-the-measurement-service)

---

## Steps to run/debug the measurement service

1. Start the discovery service if not already started.

2. (Optional)Activate related virtual environments. Measurement developers can skip this step if they are not using any [virtual environments](#create-and-manage-python-measurement-package-using-venv) or [poetry-based projects.](#create-and-manage-python-measurement-package-using-poetry)

    ```cmd
    .venv\scripts\activate
    ```

    - After successful activation, you can see the name of the environment, `(.venv)` is added to the command prompt.
    - If you face an access issue when trying to activate, retry after allowing scripts to run as Administrator by executing the below command in Windows PowerShell:

        ```cmd
        Set-ExecutionPolicy RemoteSigned 
        ```

3. [Run](https://code.visualstudio.com/docs/python/python-tutorial#_run-hello-world)/[Debug](https://code.visualstudio.com/docs/python/debugging#_basic-debugging) the measurement python file.

4. To stop the running measurement service, press `Enter` in the terminal to properly close the service.

5. (Optional)After the usage of measurement, deactivate the virtual environment. Measurement developers can skip this step if they are not using any [virtual environments](#create-and-manage-python-measurement-package-using-venv) or [poetry-based projects.](#create-and-manage-python-measurement-package-using-poetry)

    ```cmd
    deactivate
    ```

---

## Static Registration of Python Measurements

Refer to the [Static Registration of measurements section]() for the detailed steps needed to statically register a measurement.

To Statically register the examples provided, the user can copy the example directory with the service config file with the startup batch file, to the search paths and follow the [Setting up the Example Measurements](#setting-up-the-example-measurements) section to set up the measurements.

Note: The startup batch file can be modified accordingly if the user wants to run with a custom python distribution or virtual environment

### Create a batch file that runs a python measurement

The batch file used for static registration is responsible for starting the Python Scripts.

Typical Batch File:

``` cmd
"<path_to_python_exe>" "<path_to_measurement_file>"
```

Examples to start the fictitious file named `foo_measurement.py`:

1. Using the Python system distribution

    ```cmd
    python foo_measurement.py
    ```

2. Using the virtual environment

    ```cmd
    REM Windows
    .\.venv\Scripts\python.exe foo_measurement.py

    REM Linux 
    .venv/bin/python foo_measurement.py
    ```

### Create Executable for Python Scripts

To create an executable from a measurement, measurement authors can use the [pyinstaller](https://www.pyinstaller.org/) tooling. During the executable creation, the user can also embed the User Interface file using the `--add-data "<path_of_the_UI_File>;."`.

Typical Pyinstaller command to build executable.

```cmd
pyinstaller --onefile --console --add-data "<path_of_the_UI_File>;." --paths .venv\Lib\site-packages\ <path_of_the_measurement_script>
```

## API References

[Click here](https://ni.github.io/measurement-services-python/) to view the API reference documentation.

## Appendix: Managing Measurement as Python Package(Project)

Measurement and its related files can be maintained as a python package. The basic components of any Python Measurement Package are:

1. Measurement Python Module(.py file)
    - This file contains all the details related to the measurement and also contains the logic for the measurement execution.
    - This file is run to start the measurement as a service.

2. UI File
    - UI file for the Measurement. Types of supported UI files are:
        - Measurement UI(.measui): created using the **Measurement UI Editor application**.
        - LabVIEW UI(.vi)
    - The path of this file is configured by `ui_file_path` in `measurement_info` variable definition in Measurement Python Module(.py file).

Python communities have different ways of managing a python package and its dependencies. It is up to the measurement developer, on how they wanted to maintain the package and dependencies. Measurement developers can choose from a few common approaches discussed below based on their requirements.

Note: Once we have the template support for Python measurement, the approach to managing the python measurement package(project) will be streamlined and simplified.

### Create and Manage Python Measurement Package using poetry

1. Setting up Poetry(One-time setup)
    1. Make sure the system has the recommended python version installed.

    2. Install the `poetry` using the installation steps given in <https://python-poetry.org/docs/#installation>.

2. Create a new python project and add `ni-measurement-service` as a dependency to the project.

    1. Open a command prompt, and change the working directory to the directory of your choice where you want to create the project.

        ``` cmd
        cd <path_of_directory_of_your_choice>
        ```

    2. Create a python package(project) using the poetry new command. Poetry will create boilerplate files and folders that are commonly needed for a python project.

        ``` cmd
        poetry new <name_of_the_project>
        ```

    3. Add the `ni-measurement-service` package as a dependency using the [poetry add command](https://python-poetry.org/docs/cli/#add).

        ``` cmd
        cd <name_of_the_project>
        poetry add ni-measurement-service
        ```

    4. The virtual environment will be auto-created by poetry.

    5. Create measurement modules as described in ["Developing a minimal python measurement"](#developing-a-minimal-python-measurement)
        - Any additional dependencies required by measurement can be added using [add command](https://python-poetry.org/docs/cli/#add).

            ``` cmd
            poetry add <dependency_package_name>
            ```

For detailed info on managing projects using poetry [refer to the official documentation](https://python-poetry.org/docs/cli/).

### Create and Manage Python Measurement Package using venv

1. Make sure the system has the recommended python version installed.

2. Open a command prompt, and change the working directory to the directory of your choice where you want to create a project.

    ``` cmd
    cd <path_of_directory_of_your_choice>
    ```

3. Create a virtual environment.

    ``` cmd
    REM This creates a virtual environment named .venv
    python -m venv .venv
    ```

4. Activate the virtual environment. After successful activation

    ``` cmd
    .venv\scripts\activate
    REM Optionally upgrade the pip within the venv by executing the command
    python -m pip install -U pip
    ```

5. Install the `ni-measurement-service` package into the virtual environment.

    ``` cmd
    pip install ni-measurement-service
    ```

6. Create measurement modules as described in ["Developing a minimal python measurement"](#developing-a-minimal-python-measurement)
    - Any additional dependencies required by measurement can be added pip install.

        ``` cmd
        pip install <dependency_package_name>
        ```

For detailed info on managing projects with a virtual environment [refer to the official documentation](https://docs.python.org/3/tutorial/venv.html).

### Create and Manage Python Measurement Package by directly installing `ni-measurement-service` as a system-level package

Measurement developers can also install `ni-measurement-service` as a system package if necessary.

1. Install the `ni-measurement-service` package from the command prompt

    ``` cmd
    pip install ni-measurement-service
    ```

2. Create measurement modules as described in ["Developing a minimal python measurement"](#developing-a-minimal-python-measurement)

---

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ni/measurement-services-python/",
    "name": "ni-measurement-service",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "NI",
    "author_email": "opensource@ni.com",
    "download_url": "https://files.pythonhosted.org/packages/67/9b/a01e992918b5e0a2f8e4f2282db8a53d386a7cf213633a57b3bd5c8bfb7a/ni_measurement_service-0.11.1.tar.gz",
    "platform": null,
    "description": "# MeasurementLink\u2122 Support for Python\n\n- [MeasurementLink\u2122 Support for Python](#measurementlink--support-for-python)\n  - [Introduction](#introduction)\n  - [Abbreviations](#abbreviations)\n  - [Dependencies](#dependencies)\n  - [Examples](#examples)\n    - [Setting up the Example Measurements](#setting-up-the-example-measurements)\n    - [Executing the Example Measurements](#executing-the-example-measurements)\n  - [Developing Measurements: Quick Start](#developing-measurements-quick-start)\n    - [Installation](#installation)\n    - [Developing a minimal python measurement](#developing-a-minimal-python-measurement)\n  - [Steps to run/debug the measurement service](#steps-to-rundebug-the-measurement-service)\n  - [Static Registration of Python Measurements](#static-registration-of-python-measurements)\n    - [Create a batch file that runs a python measurement](#create-a-batch-file-that-runs-a-python-measurement)\n    - [Create Executable for Python Scripts](#create-executable-for-python-scripts)\n  - [API References](#api-references)\n  - [Appendix: Managing Measurement as Python Package(Project)](#appendix-managing-measurement-as-python-packageproject)\n    - [Create and Manage Python Measurement Package using poetry](#create-and-manage-python-measurement-package-using-poetry)\n    - [Create and Manage Python Measurement Package using venv](#create-and-manage-python-measurement-package-using-venv)\n    - [Create and Manage Python Measurement Package by directly installing `ni-measurement-service` as a system-level package](#create-and-manage-python-measurement-package-by-directly-installing-ni-measurement-service-as-a-system-level-package)\n\n---\n\n## Introduction\n\nMeasurementLink Support for Python (`ni-measurement-service`) is a python framework that enables measurement developers to quickly create python measurements and run them as a service (gRPC).\n\n---\n\n## Dependencies\n\n- Python >= 3.8 [(3.9 recommended)](https://www.python.org/downloads/release/python-3913/)\n- [grpcio >= 1.41.1, < 2.x](https://pypi.org/project/grpcio/1.41.1/)\n- [protobuf >= 3.20, < 4.x](https://pypi.org/project/protobuf/3.20.0/)\n- [pywin32 >= 303 (Only for Windows)](https://pypi.org/project/pywin32/303/)\n\n---\n\n## Examples\n\nThe `examples` directory contains the following example projects:  \n\n1. `sample_measurement`: Performs a loopback measurement with various data types.\n2. `nidaqmx_analog_input`: Performs a finite analog input measurement with NI-DAQmx.\n3. `nidcpower_source_dc_voltage`: Sources and measures a DC voltage with an NI SMU. Provides a Measurement UI\n4. `nidcpower_source_dc_voltage_with_labview_ui`: Sources and measures a DC voltage with an NI SMU. Provides a LabVIEW UI\n5. `nidmm_measurement`: Performs a measurement using an NI DMM.\n6. `nifgen_standard_function`: Generates a standard function waveform using an NI waveform generator.\n7. `niscope_acquire_waveform`: Acquires a waveform using an NI oscilloscope.\n8. `niswitch_control_relays`: Controls relays using an NI relay driver (e.g. PXI-2567).\n\n### Setting up the Example Measurements\n\nThe example measurements shared are *poetry-based* projects. Follow the below steps to  for setting up the example measurement:\n\n1. Install `poetry`. Refer to <https://python-poetry.org/docs/#installation> for information on installing poetry.\n\n2. Open a command prompt, and change the working directory to the directory of the example measurement you want to work with.\n\n    ``` cmd\n    cd <path_of_example_measurement>\n    REM Example: cd \"..\\measurement-services-python\\examples\\dc_measurement\"\n    ```\n\n3. Run `poetry install`. This command creates/updates the .venv and installs all the dependencies(including `ni-measurement-service` package) needed for the Example into `.venv`\n\n    ``` cmd\n    poetry install\n    ```\n    - If you get a \"command not found\" error during `poetry install`, make sure that you added the Poetry path to the system path. Refer to [https://python-poetry.org/docs/#installing-with-the-official-installer/Add-poetry-to-your-path](https://python-poetry.org/docs/#installing-with-the-official-installer:~:text=Add%20Poetry%20to%20your%20PATH)\n    ![PoetryInstallFail](PoetryInstallFail.png)\n\n### Executing the Example Measurements\n\n1. Start the discovery service if not already started.\n2. Use `poetry run` to run the measurement service:\n\n    ``` cmd\n    poetry run python measurement.py\n    ```\n\n---\n\n## Developing Measurements: Quick Start\n\nThis section provides instructions to develop custom measurement services in Python using MeasurementLink Support for Python.\n\n### Installation\n\nMake sure the system has the recommended python version is installed. Install MeasurementLink Support for Python using [pip](https://pip.pypa.io/).\n\n``` cmd\nREM Activate the required virtual environment if any.\npip install ni-measurement-service\n```\n\nCheck if you have installed the expected version of MeasurementLink Support for Python installed by running the below command:\n\n```cmd\npip show ni-measurement-service\n```\n\n### Developing a minimal python measurement\n\n1. Install the `ni-measurement-generator` package.\n\n``` cmd\nREM Activate the required virtual environment if any.\npip install ni-measurement-generator\n```\n\n2. Run the `ni-measurement-generator` tool. Use command line arguments to specify the `display-name` and optionally the `version`, `measurement-type`, and `product-type`.\n\n    1. Running `ni-measurement-generator` without optional arguments:\n\n    `ni-measurement-generator SampleMeasurement`\n\n    'SampleMeasurement' is the display name of your measurement service. Without the optional arguments,\n    the other arguments are generated for you based on the display name.\n\n    2. Running `ni-measurement-generator` with optional arguments for `measurement-version`, `ui-file`,\n    `service-class`, and `description-url`:\n\n    `ni-measurement-generator SampleMeasurement --measurement-version 0.1.0.0 --ui-file MeasurementUI.measui --service-class SampleMeasurement_Python --description-url https://www.example.com/SampleMeasurement.html`\n\n    3. Running `ni-measurement-generator` with optional argument for `directory-out`\n\n    `ni-measurement-generator SampleMeasurement --directory-out <new_path_for_created_files>`\n\n    If no output directory is specified, the files will\n    be placed in a new folder under the current directory\n    named after the display name without spaces.\n\n3. To customize the created measurement, provide metadata of the measurement's configuration(input parameters) and outputs(output parameters) in `measurement.py`.\n    1. Use the `configuration()` decorator to provide metadata about the configurations.**The order of the configuration decorator must match with the order of the parameters defined in the function signature.**\n\n        ``` python\n        @foo_measurement_service.register_measurement\n        #Display Names can not contains backslash or front slash.\n        @foo_measurement_service.configuration(\"DisplayNameForInput1\", DataType.String, \"DefaultValueForInput1\")\n        @foo_measurement_service.configuration(\"DisplayNameForInput2\", DataType.String, \"DefaultValueForInput2\")\n        def measure(input_1, input_2):\n            ''' A simple Measurement method'''\n            return [\"foo\", \"bar\"]\n        ```\n\n    2. Use the `output()` decorator to provide metadata about the output.**The order of the output decorators from top to bottom must match the order of the values of the list returned by the function.**\n\n        ``` python\n        @foo_measurement_service.register_measurement\n        @foo_measurement_service.configuration(\"DisplayNameForInput1\", nims.DataType.String, \"DefaultValueForInput1\")\n        @foo_measurement_service.configuration(\"DisplayNameForInput2\", nims.DataType.String, \"DefaultValueForInput2\")\n        @foo_measurement_service.output(\"DisplayNameForOutput1\", nims.DataType.String)\n        @foo_measurement_service.output(\"DisplayNameForOutput2\", nims.DataType.String)\n        def measure(input_1, input_2):\n            return [\"foo\", \"bar\"]\n        ```\n\n4. Run/Debug the created measurement by following the steps discussed in the section [\"Steps to run/debug the measurement service\".](#steps-to-rundebug-the-measurement-service)\n\n---\n\n## Steps to run/debug the measurement service\n\n1. Start the discovery service if not already started.\n\n2. (Optional)Activate related virtual environments. Measurement developers can skip this step if they are not using any [virtual environments](#create-and-manage-python-measurement-package-using-venv) or [poetry-based projects.](#create-and-manage-python-measurement-package-using-poetry)\n\n    ```cmd\n    .venv\\scripts\\activate\n    ```\n\n    - After successful activation, you can see the name of the environment, `(.venv)` is added to the command prompt.\n    - If you face an access issue when trying to activate, retry after allowing scripts to run as Administrator by executing the below command in Windows PowerShell:\n\n        ```cmd\n        Set-ExecutionPolicy RemoteSigned \n        ```\n\n3. [Run](https://code.visualstudio.com/docs/python/python-tutorial#_run-hello-world)/[Debug](https://code.visualstudio.com/docs/python/debugging#_basic-debugging) the measurement python file.\n\n4. To stop the running measurement service, press `Enter` in the terminal to properly close the service.\n\n5. (Optional)After the usage of measurement, deactivate the virtual environment. Measurement developers can skip this step if they are not using any [virtual environments](#create-and-manage-python-measurement-package-using-venv) or [poetry-based projects.](#create-and-manage-python-measurement-package-using-poetry)\n\n    ```cmd\n    deactivate\n    ```\n\n---\n\n## Static Registration of Python Measurements\n\nRefer to the [Static Registration of measurements section]() for the detailed steps needed to statically register a measurement.\n\nTo Statically register the examples provided, the user can copy the example directory with the service config file with the startup batch file, to the search paths and follow the [Setting up the Example Measurements](#setting-up-the-example-measurements) section to set up the measurements.\n\nNote: The startup batch file can be modified accordingly if the user wants to run with a custom python distribution or virtual environment\n\n### Create a batch file that runs a python measurement\n\nThe batch file used for static registration is responsible for starting the Python Scripts.\n\nTypical Batch File:\n\n``` cmd\n\"<path_to_python_exe>\" \"<path_to_measurement_file>\"\n```\n\nExamples to start the fictitious file named `foo_measurement.py`:\n\n1. Using the Python system distribution\n\n    ```cmd\n    python foo_measurement.py\n    ```\n\n2. Using the virtual environment\n\n    ```cmd\n    REM Windows\n    .\\.venv\\Scripts\\python.exe foo_measurement.py\n\n    REM Linux \n    .venv/bin/python foo_measurement.py\n    ```\n\n### Create Executable for Python Scripts\n\nTo create an executable from a measurement, measurement authors can use the [pyinstaller](https://www.pyinstaller.org/) tooling. During the executable creation, the user can also embed the User Interface file using the `--add-data \"<path_of_the_UI_File>;.\"`.\n\nTypical Pyinstaller command to build executable.\n\n```cmd\npyinstaller --onefile --console --add-data \"<path_of_the_UI_File>;.\" --paths .venv\\Lib\\site-packages\\ <path_of_the_measurement_script>\n```\n\n## API References\n\n[Click here](https://ni.github.io/measurement-services-python/) to view the API reference documentation.\n\n## Appendix: Managing Measurement as Python Package(Project)\n\nMeasurement and its related files can be maintained as a python package. The basic components of any Python Measurement Package are:\n\n1. Measurement Python Module(.py file)\n    - This file contains all the details related to the measurement and also contains the logic for the measurement execution.\n    - This file is run to start the measurement as a service.\n\n2. UI File\n    - UI file for the Measurement. Types of supported UI files are:\n        - Measurement UI(.measui): created using the **Measurement UI Editor application**.\n        - LabVIEW UI(.vi)\n    - The path of this file is configured by `ui_file_path` in `measurement_info` variable definition in Measurement Python Module(.py file).\n\nPython communities have different ways of managing a python package and its dependencies. It is up to the measurement developer, on how they wanted to maintain the package and dependencies. Measurement developers can choose from a few common approaches discussed below based on their requirements.\n\nNote: Once we have the template support for Python measurement, the approach to managing the python measurement package(project) will be streamlined and simplified.\n\n### Create and Manage Python Measurement Package using poetry\n\n1. Setting up Poetry(One-time setup)\n    1. Make sure the system has the recommended python version installed.\n\n    2. Install the `poetry` using the installation steps given in <https://python-poetry.org/docs/#installation>.\n\n2. Create a new python project and add `ni-measurement-service` as a dependency to the project.\n\n    1. Open a command prompt, and change the working directory to the directory of your choice where you want to create the project.\n\n        ``` cmd\n        cd <path_of_directory_of_your_choice>\n        ```\n\n    2. Create a python package(project) using the poetry new command. Poetry will create boilerplate files and folders that are commonly needed for a python project.\n\n        ``` cmd\n        poetry new <name_of_the_project>\n        ```\n\n    3. Add the `ni-measurement-service` package as a dependency using the [poetry add command](https://python-poetry.org/docs/cli/#add).\n\n        ``` cmd\n        cd <name_of_the_project>\n        poetry add ni-measurement-service\n        ```\n\n    4. The virtual environment will be auto-created by poetry.\n\n    5. Create measurement modules as described in [\"Developing a minimal python measurement\"](#developing-a-minimal-python-measurement)\n        - Any additional dependencies required by measurement can be added using [add command](https://python-poetry.org/docs/cli/#add).\n\n            ``` cmd\n            poetry add <dependency_package_name>\n            ```\n\nFor detailed info on managing projects using poetry [refer to the official documentation](https://python-poetry.org/docs/cli/).\n\n### Create and Manage Python Measurement Package using venv\n\n1. Make sure the system has the recommended python version installed.\n\n2. Open a command prompt, and change the working directory to the directory of your choice where you want to create a project.\n\n    ``` cmd\n    cd <path_of_directory_of_your_choice>\n    ```\n\n3. Create a virtual environment.\n\n    ``` cmd\n    REM This creates a virtual environment named .venv\n    python -m venv .venv\n    ```\n\n4. Activate the virtual environment. After successful activation\n\n    ``` cmd\n    .venv\\scripts\\activate\n    REM Optionally upgrade the pip within the venv by executing the command\n    python -m pip install -U pip\n    ```\n\n5. Install the `ni-measurement-service` package into the virtual environment.\n\n    ``` cmd\n    pip install ni-measurement-service\n    ```\n\n6. Create measurement modules as described in [\"Developing a minimal python measurement\"](#developing-a-minimal-python-measurement)\n    - Any additional dependencies required by measurement can be added pip install.\n\n        ``` cmd\n        pip install <dependency_package_name>\n        ```\n\nFor detailed info on managing projects with a virtual environment [refer to the official documentation](https://docs.python.org/3/tutorial/venv.html).\n\n### Create and Manage Python Measurement Package by directly installing `ni-measurement-service` as a system-level package\n\nMeasurement developers can also install `ni-measurement-service` as a system package if necessary.\n\n1. Install the `ni-measurement-service` package from the command prompt\n\n    ``` cmd\n    pip install ni-measurement-service\n    ```\n\n2. Create measurement modules as described in [\"Developing a minimal python measurement\"](#developing-a-minimal-python-measurement)\n\n---\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "MeasurementLink Support for Python",
    "version": "0.11.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "c653ed009cb24e858ac865a826fe45aa",
                "sha256": "77416758025b9d84840be25eefe39cb61c1c6ee5914ea9ce2f3202aa4bbb3938"
            },
            "downloads": -1,
            "filename": "ni_measurement_service-0.11.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c653ed009cb24e858ac865a826fe45aa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 70251,
            "upload_time": "2022-12-08T23:21:03",
            "upload_time_iso_8601": "2022-12-08T23:21:03.978313Z",
            "url": "https://files.pythonhosted.org/packages/cd/86/39656174759d39cb4a10967912cdf753af28b7c8c1e7e8ebcc659f165aaf/ni_measurement_service-0.11.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "e2d691277f858bfb51a600de63f4b66c",
                "sha256": "4f566b76171e52d201292d78a2b25535776592bbb7c34b5bcb1b7fb38c2ea3ba"
            },
            "downloads": -1,
            "filename": "ni_measurement_service-0.11.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e2d691277f858bfb51a600de63f4b66c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 57362,
            "upload_time": "2022-12-08T23:21:06",
            "upload_time_iso_8601": "2022-12-08T23:21:06.132070Z",
            "url": "https://files.pythonhosted.org/packages/67/9b/a01e992918b5e0a2f8e4f2282db8a53d386a7cf213633a57b3bd5c8bfb7a/ni_measurement_service-0.11.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-08 23:21:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "ni",
    "github_project": "measurement-services-python",
    "lcname": "ni-measurement-service"
}
        
NI
Elapsed time: 0.03159s