Skip to main content

Developing plugins for Nellie

Nellie is a Napari plugin designed for automated organelle segmentation, tracking, and hierarchical feature extraction in 2D/3D live-cell microscopy. To extend its capabilities and foster a collaborative ecosystem, Nellie supports additional plugins that integrate seamlessly with its core functionality.

This guide provides a step-by-step workflow for developers to create, package, and distribute their own Nellie plugins, making them easily installable via pip and accessible through the Napari interface under the Plugins -> Nellie plugins submenu.

Understanding the Nellie Plugin System

How the Plugin System Works

1. Entry Points Mechanism

Nellie leverages Python’s entry_points mechanism to discover and load plugins dynamically. Entry points are a way for Python packages to advertise components (like functions or classes) that can be used by other packages at runtime.

  • Entry Point Group: Nellie defines a specific entry point group called nellie.plugins. Plugins register their functions under this group.
  • Registration: When a plugin is installed (typically via pip), the entry points declared in its setup.py or pyproject.toml are registered in the Python environment.
  • Discovery: Nellie scans the nellie.plugins entry point group to find all registered plugins.

2. Plugin Discovery and Loading in Nellie

When Nellie is loaded within Napari:

  • Scanning for Plugins: Nellie uses the importlib.metadata.entry_points (or pkg_resources.iter_entry_points for older Python versions) to retrieve all entry points under the nellie.plugins group.
  • Loading Plugin Functions: Each discovered entry point is loaded, obtaining a reference to the plugin function.
  • Building the Menu: Nellie adds each plugin to the Napari menu under Plugins -> Nellie, allowing users to easily access the additional functionality.

3. Integration with Napari

  • Napari Plugin Architecture: While Napari has its own plugin system, Nellie’s plugin system operates within its own namespace to maintain a cohesive user experience.
  • Menu Hierarchy: Plugins registered under Nellie’s system appear in a dedicated submenu, ensuring they are easily distinguishable from other Napari plugins.
  • User Interaction: When a user selects a Nellie plugin from the menu, the corresponding function is invoked, allowing the plugin to interact with the napari_viewer and Nellie’s data.

Example Workflow for Plugin Developers:

  1. Write the Plugin Function:
# plugin_module.py
def nellie_plugin_function(napari_viewer):
   # Access Nellie's outputs and perform custom processing
   pass
  1. Set Up setup.py:
from setuptools import setup

setup(
    name='my-nellie-plugin',
    version='0.1.0',
    py_modules=['plugin_module'],
    entry_points={
        'nellie.plugins': [
            'Custom Plugin Name = plugin_module:nellie_plugin_function',
        ],
    },
)
  1. Distribute the Plugin: Publish the plugin to PyPI or share it so users can install it via
pip install my-nellie-plugin.

Distributing the plugin

1. Install Build Tools:

Make sure you have the latest versions of setuptools and wheel:

pip install --upgrade setuptools wheel

2. Build the Package:

From the root directory of your project (where setup.py is located), run:

python setup.py sdist bdist_wheel

This will create a dist/ directory containing:

  • A source distribution (.tar.gz)
  • A built distribution wheel (.whl)

3. Upload Your Package to PyPI

To upload your package to PyPI, you’ll use the twine tool. a. Create a PyPI Account:

  • Go to PyPI and create an account if you don’t have one.
  • Verify your email address.

b. Install Twine:

pip install --upgrade twine

c. Test Your Package with TestPyPI (Optional but Recommended): Upload to TestPyPI:

  • TestPyPI is a separate instance of PyPI for testing.
  • Create an account on TestPyPI.
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

Test Installation from TestPyPI:

pip install --index-url https://test.pypi.org/simple/ my-nellie-plugin

d. Upload to PyPI: When you’re ready to release your Nellie plugin publicly:

twine upload dist/*

4. Verify Installation

After uploading to PyPI, verify that your package can be installed and works as expected.

a. Install Your Plugin:

pip install my-nellie-plugin

b. Test the Plugin in Napari with Nellie:

  • Open Napari.
  • Load Nellie, then ensure your plugin appears under Plugins -> Nellie plugins -> Custom Plugin Name.
  • Test the functionality to confirm everything works as intended.

Summary of the Plugin Workflow

  1. Plugin Function Definition: Create a function that accepts napari_viewer and implements your desired functionality.
  2. Entry Point Registration: Register your plugin function under the nellie.plugins entry point group in your setup.py.
  3. Packaging and Distribution: Package your plugin using standard Python packaging tools and distribute it via PyPI or other means.
  4. Installation by Users: Users install your plugin via pip, which registers the entry points.
  5. Plugin Discovery by Nellie: When Nellie initializes, it discovers all installed plugins registered under nellie.plugins.
  6. Integration into Napari: Plugins are added to the Napari menu under Plugins -> Nellie, providing easy access for users.
  7. Execution: When a user selects your plugin from the menu, your function is called with the napari_viewer, allowing you to interact with both Nellie and Napari.

Additional Resources

Frequently Asked Questions

Q: How does Nellie discover plugins at runtime?

A: Nellie uses the Python entry_points mechanism to discover plugins. When Nellie initializes, it queries the nellie.plugins entry point group to find all registered plugin functions. These functions are then loaded and integrated into the Napari interface.

Q: Do I need to modify Nellie’s source code to add my plugin?

A: No, you don’t need to modify Nellie’s source code. By registering your plugin via entry points and ensuring it’s installed in the Python environment, Nellie can automatically discover and integrate your plugin.

Q: Can my plugin have its own dependencies?

A: Yes, you can specify any dependencies your plugin requires in the install_requires section of your setup.py. These dependencies will be installed automatically when users install your plugin via pip.

Q: What versions of Python are supported?

A: Ensure that your plugin is compatible with the Python versions supported by Nellie and Napari. Typically, supporting Python 3.9 and above is recommended.

Q: Can I contribute my plugin back to the Nellie project?

A: Absolutely! If you believe your plugin adds valuable functionality that would benefit the broader user base, consider contributing it back to the Nellie project. You can submit a pull request or contact the maintainers (aka me, Austin) for more information.

Metadata

Release files for my-nellie-plugin 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for my-nellie-plugin 0.1.4
File Size Uploaded Provenance Actions
my_nellie_plugin-0.1.4.tar.gz 5.1 kB Without provenance Details for my_nellie_plugin-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for my-nellie-plugin 0.1.4
File Interpreter ABI Platform Actions
my_nellie_plugin-0.1.4-py3-none-any.whl Python 3 none any Details for my_nellie_plugin-0.1.4-py3-none-any.whl

Total release size: 10.6 kB

Release files / my_nellie_plugin-0.1.4.tar.gz

Download URL my_nellie_plugin-0.1.4.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4142197f866710d4ca6cae2adb84737d0b5427fa7d8107143aed9501aad7b91b
BLAKE2b-256 checksum
How to use checksums
a138aaff6f03a4eee4001600f9790bf41838569bd4c372f033e60755c6f74562
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / my_nellie_plugin-0.1.4-py3-none-any.whl

Download URL my_nellie_plugin-0.1.4-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49927c93476380bc062680a78928fa2256fd65a81b134878d7f4a6a0ced22c47
BLAKE2b-256 checksum
How to use checksums
fd3dbfef51818ea7dd3fa172f959a1ee7a3267421d3ca87ea7a601da50e848e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Security for my-nellie-plugin 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page