# Expose multiple modules from a single package

**URL:** <https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745>\
**Category:** General Usage\
**Created:** [August 11, 2020, 2:32pm UTC](https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745 "2020-08-11T14:32:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![benninkrs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benninkrs/32/3191_2.png) [@benninkrs](https://discourse.julialang.org/u/benninkrs)\
**Post date:** [August 11, 2020, 2:32pm UTC](https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745/1 "2020-08-11T14:32:27Z")

</div>

I have a question that was discussed a few years ago [here](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615) and [here](https://stackoverflow.com/questions/30783197/can-i-make-a-julia-package-containing-multiple-modules-that-can-be-independently), but those discussions seem to be outdated as none of the solutions given there work for me.

Say I have a package `MyPackage` with a module `MyPackage.jl` that provides the main functionality and some modules `OptionalModule1`, `OptionalModule2`, etc. that provide optional functionality. I want the user to be able to access these optional modules with something like

```julia
using MyPackage
using OptionalModule2

```

or perhaps

```julia
using MyPackage
using MyPackage.OptionalModule2

```

While the optional modules could be made submodules of the main module, I don’t want the overhead of loading a bunch of optional modules the user may not want.

Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 11, 2020, 2:41pm UTC](https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745/2 "2020-08-11T14:41:49Z")

</div>

Of course, I do that all the time in [FinEtools](https://github.com/PetrKryslUCSD/FinEtools.jl). I include the modules in the top module.

---

<div class="post-metadata">

**Author:** ![benninkrs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benninkrs/32/3191_2.png) [@benninkrs](https://discourse.julialang.org/u/benninkrs)\
**Post date:** [August 11, 2020, 2:59pm UTC](https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745/3 "2020-08-11T14:59:23Z")

</div>

But including modules causes them to be immediately loaded, whether the user wants to use them or not. I was asking if there is a way to make the modules available for loading _if and when_ the user wants them, so that modules not requested by the user don’t incur any needless overhead.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 11, 2020, 3:02pm UTC](https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745/4 "2020-08-11T15:02:16Z")

</div>

I see. But selective optimization levels may be of help here, perhaps?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 11, 2020, 3:05pm UTC](https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745/5 "2020-08-11T15:05:46Z")

</div>

On second thought: would it make sense to split up the package then? Perhaps what is optional is distinct enough from the basic functionality that it warrants its own package?

---

<div class="post-metadata">

**Author:** ![benninkrs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benninkrs/32/3191_2.png) [@benninkrs](https://discourse.julialang.org/u/benninkrs)\
**Post date:** [August 11, 2020, 3:27pm UTC](https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745/6 "2020-08-11T15:27:14Z")

</div>

It could be that the overhead isn’t as big of a concern as I fear. If the submodules support precompiling, then in principle the overhead of parsing and compiling would only be incurred once. But IIUC they would still take up memory.

Making them separate packages is valid suggestion, but in my case the optional modules really only make sense in the context of the main package.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 11, 2020, 3:32pm UTC](https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745/7 "2020-08-11T15:32:01Z")

</div>

Yes, I made the same decision. But FinEtools used to be a lot bigger. So while it has “optional” modules that are still part of the basic package but need to be `using`ed separately, most of the functionality has been separated out into individual packages.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 11, 2020, 3:45pm UTC](https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745/8 "2020-08-11T15:45:18Z")

</div>

Cf

[https://github.com/JuliaLang/Pkg.jl/issues/1928](https://github.com/JuliaLang/Pkg.jl/issues/1928)

---

<div class="post-metadata">

**Author:** ![benninkrs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benninkrs/32/3191_2.png) [@benninkrs](https://discourse.julialang.org/u/benninkrs)\
**Post date:** [August 11, 2020, 4:09pm UTC](https://discourse.julialang.org/t/expose-multiple-modules-from-a-single-package/44745/9 "2020-08-11T16:09:23Z")

</div>

Thanks. The precursor of that topic is actually very relevant. It addresses a number of distinct issues, but the behavior proposed by @tim.holy and @kristoffer.carlsson in [#1874](https://github.com/JuliaLang/Pkg.jl/issues/1874#issuecomment-649418577) is very similar to what I am looking for.
