# Multiple modules in single package

**URL:** <https://discourse.julialang.org/t/multiple-modules-in-single-package/5615>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 28, 2017, 1:38pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615 "2017-08-28T13:38:56Z")\
**Posts on this page:** 16\
**Page:** 1

<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 28, 2017, 1:38pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/1 "2017-08-28T13:38:56Z")

</div>

I found that a rather short function I use in the unit tests of a package would be useful somewhere else. If I don’t want to make a separate _package_ for it, is it possible to put it in a _separate module in the same package_?

Simply putting it in `src/MiniModule.jl` in the same package does not make `using MiniModule` find it it.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [August 28, 2017, 2:08pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/2 "2017-08-28T14:08:28Z")

</div>

It would need to be a submodule, I think. To get it `using MyPkg.MiniModule` ain’t so bad.

---

<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 28, 2017, 2:17pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/3 "2017-08-28T14:17:09Z")

</div>

That’s unfortunate: `MiniModule` is not really related to `MyPkg`, other than being useful in its unit tests.

It seems that, there is an implicit 1:1 mapping between modules and packages for many things.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [August 28, 2017, 5:13pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/5 "2017-08-28T17:13:51Z")

</div>

How would you want it to be accessible? As soon as you think about that, it sounds like a julia package.

Packages con be small and minimal. What is the exact issue you are worried about?

---

<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 28, 2017, 6:09pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/6 "2017-08-28T18:09:18Z")

</div>

> [@dpsanders](#):
>
> What is the exact issue you are worried about?

Making a package for \<10 LOC. But I see your point.

---

<div class="post-metadata">

**Author:** ![JaredCrean2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaredcrean2/32/3574_2.png) [@JaredCrean2](https://discourse.julialang.org/u/JaredCrean2)\
**Post date:** [August 28, 2017, 6:14pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/7 "2017-08-28T18:14:49Z")

</div>

You can also do `push!(LOAD_PATH, @ __DIR__ )` in `src/Module.jl` to make `MiniModule` findable. Then users can do `using Module; using MiniModule`

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [August 28, 2017, 6:15pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/8 "2017-08-28T18:15:50Z")

</div>

> [@dpsanders](#):
>
> What is the exact issue you are worried about?

At least if registered it does put additional burden on METADATA maintainers (and on Tamas too).

---

<div class="post-metadata">

**Author:** ![JoshLangsfeld](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshlangsfeld/32/8211_2.png) [@JoshLangsfeld](https://discourse.julialang.org/u/JoshLangsfeld)\
**Post date:** [August 28, 2017, 7:54pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/9 "2017-08-28T19:54:46Z")

</div>

There was some discussion on this topic here: [https://github.com/JuliaLang/Juleps/issues/8](https://github.com/JuliaLang/Juleps/issues/8)

I’m really hoping to see this feature before 1.0; I don’t think having to use a separate git repository for every chunk of code that forms a standalone module is really scalable for huge projects.

---

<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:** [December 11, 2018, 12:15pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/10 "2018-12-11T12:15:57Z")

</div>

Sorry for necroing this thread, but I assume that those who replied may be interested.

I think found a Pkg3-compatible solution. Let’s call the package `ThePackage` and the auxiliary module `AuxModule`.

1. Have the auxiliary module in a subdirectory of the main project, eg `assets/AuxModule/src/AuxModule.jl`.
2. `pkg> activate` the _main_ project.
3. `pkg> dev ./assets/AuxModule`. This will generate an UUID for it, even if there is no `Project.toml` file in `assets/AuxModule`.

Then it appears that when the package is activated again, `using AuxModule` etc will work fine. One just needs to make sure that the project was activated.

This solves my problem, but I am unsure if it is something I can count on to keep working, or an abuse of the Pkg3 setup. Comments welcome.

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [December 11, 2018, 12:54pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/11 "2018-12-11T12:54:44Z")

</div>

I think this is how it’s intended to work, judging by this comment: [Pkg3: package namespaces · Issue #8 · JuliaLang/Juleps · GitHub](https://github.com/JuliaLang/Juleps/issues/8#issuecomment-400829383)

---

<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:** [December 11, 2018, 12:55pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/12 "2018-12-11T12:55:39Z")

</div>

Note that my solution is without making `AuxModule` a submodule.

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [September 17, 2020, 4:34pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/13 "2020-09-17T16:34:10Z")

</div>

Necroing the thread again. Does this solution still work? I’m getting

```julia
ERROR: expected a `uuid` entry in project file at...

```

and, even if I ignore it, I have no success.

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [September 17, 2020, 4:51pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/14 "2020-09-17T16:51:07Z")

</div>

Did a “generate”, got a uuid, and all seems to be well. The Manifest.toml says exactly the right thing. However, if I put the Manifest.toml on github, will that break CI?

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [September 17, 2020, 5:20pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/15 "2020-09-17T17:20:26Z")

</div>

It seems to be trickier than that. When I try to get the AuxModule to load from a notebook, IJulia can’t find it. Nor does it work in the REPL after a restart of Julia.

The item in @Per’s post  
[https://github.com/JuliaLang/Juleps/issues/8#issuecomment-400829383](https://github.com/JuliaLang/Juleps/issues/8#issuecomment-400829383)  
seems to say that I need to load it as a separate package from the same repo. I’d prefer not to do that because it will be confusing for my users.

---

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [March 15, 2023, 6:10pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/16 "2023-03-15T18:10:30Z")

</div>

Related to this, I think the [FastAI.jl](https://github.com/FluxML/FastAI.jl) package contains multiple modules (not submodules) in it:

- FastAI
- FastMakie
- FastTabular
- FastText
- FastTimeSeries
- FastVision

Only the FastAI module is defined in the top `src/` directory of the package; the remaining modules are defined in their own directories, and they all have their own `Project.toml` and `src/` directories.

I’m not sure how this is done; I wonder if @holylorenzo could explain how.

**[Update]** It seems misleading to say that the FastAI.jl package contains multiple modules. It seems that all these modules (FastVision, FastTabular, etc) are all packages on their own, because after I install FastAI and try `using FastVision`, the package manager asks me to install `FastVision` (even though FastAI is already installed). So, it seems more correct to say that the single GitHub repository at [GitHub - FluxML/FastAI.jl: Repository of best practices for deep learning in Julia, inspired by fastai](https://github.com/FluxML/FastAI.jl) contains multiple packages.

---

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [April 3, 2023, 2:59pm UTC](https://discourse.julialang.org/t/multiple-modules-in-single-package/5615/17 "2023-04-03T14:59:21Z")

</div>

Another, probably more familiar case where multiple packages are included in a single repository: [Makie.jl](https://github.com/MakieOrg/Makie.jl). It contains several packages like Makie.jl, CairoMakie.jl, GLMakie.jl.

So, putting multiple packages in a single Git repository seems like a widely used practice at this point.
