# Public package as plugin

**URL:** <https://discourse.julialang.org/t/public-package-as-plugin/69911>\
**Category:** General Usage\
**Tags:** question, module\
**Created:** [October 16, 2021, 8:12pm UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911 "2021-10-16T20:12:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kalcool](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kalcool](https://discourse.julialang.org/u/kalcool)\
**Post date:** [October 16, 2021, 8:12pm UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/1 "2021-10-16T20:12:57Z")

</div>

Hi there,

I am developing a program that should have a plugin system. I am thinking of using Julia’s package system for this purpose. The idea is that you install a Julia package with additional functionality and when you run the program this functionality activates. This doesn’t sound too hard, but here is the catch

I don’t want my program to know in advance what extension packages exist. I hope other people can write these plugin packages and just by installing them, my program finds them when it runs.

- Is this possible?
- How would you go about it?
- Is it a good idea?

Cheers,  
kalcool

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 16, 2021, 8:14pm UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/2 "2021-10-16T20:14:03Z")

</div>

this happens all the time, for example when you load `LoopVectorization` it enables `Tullio`, or any of the million packages that have Plotting recipe for their objects, they extends `Plots.plot`

---

<div class="post-metadata">

**Author:** ![kalcool](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kalcool](https://discourse.julialang.org/u/kalcool)\
**Post date:** [October 16, 2021, 8:27pm UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/3 "2021-10-16T20:27:56Z")

</div>

Maybe I am missing something, but in this case the user must introduce an object of a new type and call the function so the extension is used, right? So to call the function the object would have to be part of the code of my program already.  
Therefore I think introducing new function signatures would not solve my problem by itself  
and overloading an existing function signature would also not work, because multiple plugins cannot share that overloaded function.

To illustrate: Imagine my program has the routine runPlugins(x) which is normally empty, a new package could add a signature runPlugins(i::Int32), but my program would have to call runPlugins with an integer, so it needs to know in advance the type of arguments to use, to trigger the new function for each plugin. I don’t know exactly what is possible with new packages so if overwriting the runPlugins(x) function of the main program is possible. Plugin 1 could supply a runPlugins function and Plugin2 could supply a run plugins function, but my programs runPlugins() function should run those functions sequentially, and not just one of them.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 16, 2021, 8:30pm UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/4 "2021-10-16T20:30:55Z")

</div>

the new package you loaded can completely change the behavior of an existing function, but that’s really bad practice, and I honestly don’t know what’s good with that.

Do you have a concrete use case example?

---

<div class="post-metadata">

**Author:** ![kalcool](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kalcool](https://discourse.julialang.org/u/kalcool)\
**Post date:** [October 16, 2021, 8:37pm UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/5 "2021-10-16T20:37:24Z")

</div>

Imagine a graphics editor. Let’s say I would like to have Gaussian blur as a plugin and invert colors as a plugin. If both packages are installed the editor should show one button for each to manipulate the picture. If either one, two or none of the plugins are installed, the editor should show the appropriate number of buttons.  
But again my program should not know in advance what buttons can exist, so plugin writers don’t need write access to my code repository.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 16, 2021, 8:41pm UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/6 "2021-10-16T20:41:18Z")

</div>

ok, the kind of plugin system you described should NOT be at the language level. It should be part of your software, ecosystem logic.

In other words, the “loading a plugin” should not translate to `using some_plugin` directly in Julia.

---

<div class="post-metadata">

**Author:** ![kalcool](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kalcool](https://discourse.julialang.org/u/kalcool)\
**Post date:** [October 16, 2021, 8:45pm UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/7 "2021-10-16T20:45:42Z")

</div>

So you say it’s a bad idea. Could you elaborate on why? Or is it impossible? Because a lot of functionality that I would like to have for my plugins, seems to come for free with Julia’s package management.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 16, 2021, 8:48pm UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/8 "2021-10-16T20:48:41Z")

</div>

I’m saying you need to implement your software logic additionally. Because a plugin is fundamentally different than a package – it’s possible for packages to extend and specialize each other’s behavior, but you can’t have a “manager” dynamically populate some menu data structure based on how many and what packages you loaded (it will be extremely hacky); not to mention how to communicate what plugin applies to what, you need your plugin specification for this (which can involve Julia types, for example `AbstractPlugin`, and then `AbstractFilter <: AbstractPlugin`)

---

<div class="post-metadata">

**Author:** ![kalcool](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kalcool](https://discourse.julialang.org/u/kalcool)\
**Post date:** [October 16, 2021, 8:57pm UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/9 "2021-10-16T20:57:13Z")

</div>

OK. Thank you. I’ll wait see if there are more suggestions that don’t look super hacky and otherwise I’ll look for another solution.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 17, 2021, 12:40am UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/10 "2021-10-17T00:40:10Z")

</div>

The **init** functions of the plugins could populate the menu (by pushing the new features to a shared list). Isn’t that possible?

---

<div class="post-metadata">

**Author:** ![kalcool](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kalcool](https://discourse.julialang.org/u/kalcool)\
**Post date:** [October 20, 2021, 9:36am UTC](https://discourse.julialang.org/t/public-package-as-plugin/69911/11 "2021-10-20T09:36:55Z")

</div>

o.k. so have looked into using ` __init__ `, and this can probably work. I can check if a package is installed using Pkg.installed() or Pkg.dependencies(). What I am missing now is a way to do `using` on a Package specified by a String.

```julia
using "Modulename"

```

doesn’t work and neither does

```julia
using Symbol("Modulname")

```

Do you have any ideas for that?
