Skip to content

Methods

Next, I present all methods used in py4pd object. The methods are messages that you can send to the object. The methods are:

  • set

    It loads the Python function.

  • pip

    To install packages. pip install install packages, pip target which folder install the packages.

  • run

    It runs the Python function.

  • pointers

    On/Off the Python Data output.

  • doc

    Print the documentation of the Python function.

  • open

    Open a loaded script.

  • editor

    Set the editor to open Python Scripts.

  • create

    Create a new .py script.

  • reload

    Reload the Python Function.

  • home

    Set the Python Home folder.

  • packages

    Set the Python Packages folder (where Python searches for Packages).

  • version

    Print the Version of py4pd and Python.


set

Set the function for the object.

  • Arguments


    Parameters Type Description
    arg1 symbol Python Script name (never uses
    arg2 anything Args for the function
  • Example

    Set method example

    Tip

    If you will always use the same function, you can create the object with the py4pd script function.


pip

When you set some function and see some error related to ModuleNotFoundError: No module named some module, you need to use pip to install this module.

  • Arguments


    Parameters Type Description
    arg1 symbol must be install
    arg2 modulename Module name to install
    Note

    You can also use pip target to change the folder where py4pd will install the modules. pip target local will install the modules inside the patch folder. pip install global will install in the py4pd folder. Global installations are the default.

  • Example

    Set method example


run

Used to run the Python Functions.

  • Arguments


    Parameters Type Description
    Arguments anything Arguments for the function
  • Example

    Set method example


pointers

You can work with Python Data types inside PureData. With this, you can work with any data type provided by Python inside PureData.

  • Arguments


    Parameters Type Description
    on/off 1 or 0 1 for on 0 for off
  • Example

    Set method example


doc

It prints on PureData the documentation of the Python Function (if it exists).

  • Arguments


    There is no Arguments.

    Note

    The creator of the function must provide some documentation.

  • Example

    Set method example


open

It opens py script files, in case the file does not exist in the patch folder, it creates a new Python Script. open score, for example, will open the score.py (if it exists) or create score.py.

  • Arguments


    Parameters Type Description
    args symbol script file name without extension .py.
  • Example

    Set method example


create

It creates a new script in the patch folder.

  • Arguments


    Parameters Type Description
    args symbol script file name without extension .py.
  • Example

    Set method example


editor

Without arguments, it opens the Python Script loaded with the message set. With one symbol args, you can choose between four IDE: vscode, nvim,emacs, orsublime`. The function must be loaded first.

  • Arguments


    Parameters Type Description
    arg1 symbol vscode, nvim, emacs and sublime.
  • Example

    Set method example

    Tip

    If a function is loaded, clicking on the object will open the loaded function too.


reload

If you are working on a Python Script and changing the code, you need to send this message to the py4pd for the changes to be loaded.

  • Arguments

    There are no Arguments.

  • Example

    Set method example


home

Set the home for Python. It is similar to executing Python from some specific folder. For example, when we use cd Downloads then python myscript.py in the same terminal.

  • Arguments

    Parameters Type Description
    arg1 symbol Folder that will be the HOME for Python Script.
  • Example

    Set method example


packages

Set the package path for Python. py4pd will look for external modules inside these folders. For example, if you have one virtual environment called composition`` with miniconda, you can sendpackages ~/miniconda3/envs/composition/lib/python3.11/site-packages` to use the installed packages.

  • Arguments

    Parameters Type Description
    arg1 symbol Folder that will be the HOME for Python packages.
  • Example

    Set method example

version

Output the version of the installed py4pd and the version of Python.

  • Arguments

    There is no Arguments.

  • Example

    Set method example