Skip to content

Methods

Next, I present all methods used in py4pd object. But the three main 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.

  • functions

    Print all the functions inside a script.

  • reload

    Reload the Python Function.

  • home

    Set the Python Home folder.

  • packages

    Set the Python Packages folder (where Python search 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 with ModuleNotFoundError: No module named somemodule, 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 exits).

  • 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, 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 or sublime. 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, click in 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 is no Arguments.

  • Example

    Set method example


home

Set the home for Python. It is similar to execute 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 packages path for Python. py4pd will look for external modules inside this folders. For example, if you one virtual enviroment called composition with miniconda, you can send packages ~/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