# How to dynamically import packages and run their functions from a setting file

**URL:** <https://discourse.julialang.org/t/how-to-dynamically-import-packages-and-run-their-functions-from-a-setting-file/119548>\
**Category:** General Usage\
**Created:** [September 18, 2024, 12:36pm UTC](https://discourse.julialang.org/t/how-to-dynamically-import-packages-and-run-their-functions-from-a-setting-file/119548 "2024-09-18T12:36:03Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [September 18, 2024, 4:38pm UTC](https://discourse.julialang.org/t/how-to-dynamically-import-packages-and-run-their-functions-from-a-setting-file/119548/2 "2024-09-18T16:38:50Z")

</div>

I don’t exactly understand what you want. Do you want to load packages conditionally, based on a parameter file? You might need `@eval` to do that (a symptom that there is probably a better way to accomplish your goals). You might find `using Pkg; Pkg.project().dependencies` to be useful for finding what is in your project (although this may not be the best way – this kind of introspection isn’t super-well supported because it’s not usually very useful). If you’re thinking about this, I’ll discourage it and say that there’s probably a better way. If you elaborate a little bit, someone can probably suggest it.

* * *

In any case, your `MainPackage` does not need to import, depend on, or even know about your optional packages. More idiomatically, your `MainPackage` might define an interface (a set of abstract types and/or functions) and your optional packages would extend it with their custom functionality. So your optional packages would depend on your main package (not so onerous when they intend to implement/extend its functionality), but not the other way around.

An example of the pattern I would propose is given in [this post](https://discourse.julialang.org/t/module-parameters-and-run-time-efficiency/119505/4). This is basically the same way any interface in Julia is extended (for example, how one implements a custom `AbstractArray`) except that in this case the dispatch is based on a token (that may hold no data) instead of some data-carrying object (like an `AbstractArray`).

---

_[View the full topic](https://discourse.julialang.org/t/how-to-dynamically-import-packages-and-run-their-functions-from-a-setting-file/119548)._
