# What are the steps to create your own package in Julia?

**URL:** <https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877>\
**Category:** New to Julia\
**Tags:** package, first-steps\
**Created:** [June 6, 2020, 2:20pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877 "2020-06-06T14:20:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rop11](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rop11](https://discourse.julialang.org/u/rop11)\
**Post date:** [June 6, 2020, 2:20pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/1 "2020-06-06T14:20:52Z")

</div>

New question on Julia related forum:  
What are the steps to create your own package in Julia?

[https://www.stemiac.com/forum/julia-programming/what-are-the-steps-to-create-your-own-package-in-julia/](https://www.stemiac.com/forum/julia-programming/what-are-the-steps-to-create-your-own-package-in-julia/)

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [June 6, 2020, 3:58pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/2 "2020-06-06T15:58:10Z")

</div>

I am not a package developer but I think something that’s important in the Julia ecosystem is the use of `Project.toml` and `Manifest.toml` files that define an environment. It took me a very long time to understand how environments work in Julia so it might be worth your while to understand it well.

Second, is the use of multithreading and distributed parallel computing. Likely your code wont use distributed computing (i.e. `addprocs`, `pmap`, `spawn` and family of functions), but likely can use multithreading to speed up code. What happens when the user tries to run your function across many threads and your function itself is also using threads. There was a great video on how this “nested” parallelism works, but I can’t seem to find it right now

---

<div class="post-metadata">

**Author:** ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)\
**Post date:** [June 6, 2020, 4:01pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/3 "2020-06-06T16:01:18Z")

</div>

There are two very convenient tools for that:

1. setting files up via [GitHub - invenia/PkgTemplates.jl: Create new Julia packages, the easy way](https://github.com/invenia/PkgTemplates.jl)
2. registration via [JuliaHub](https://juliahub.com/ui/index.html)

---

<div class="post-metadata">

**Author:** ![rop11](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rop11](https://discourse.julialang.org/u/rop11)\
**Post date:** [June 6, 2020, 5:04pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/4 "2020-06-06T17:04:12Z")

</div>

What does new package needs to provide in order to be officially accepted?  
How to use existing packages while building your own new package?

---

<div class="post-metadata">

**Author:** ![virtualgraham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/virtualgraham/32/15200_2.png) [@virtualgraham](https://discourse.julialang.org/u/virtualgraham)\
**Post date:** [June 6, 2020, 10:40pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/5 "2020-06-06T22:40:16Z")

</div>

The General Registry is not a curated list, so there is minimal moderation. There are some automatic tests your code has to pass. These include checking the version, name, dependencies are all according to the guidelines and it builds and runs.

> **[GitHub - JuliaRegistries/General: The official registry of general Julia...](https://github.com/JuliaRegistries/General#automatic-merging-of-pull-requests)**
>
> The official registry of general Julia packages. Contribute to JuliaRegistries/General development by creating an account on GitHub.

Your package should have a `Project.toml` file and that file should have a dependency section where you specify which existing packages you are using. [10. Project.toml and Manifest.toml · Pkg.jl](https://julialang.github.io/Pkg.jl/v1/toml-files/)

---

<div class="post-metadata">

**Author:** ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)\
**Post date:** [June 6, 2020, 11:21pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/6 "2020-06-06T23:21:09Z")

</div>

In addition to those minimal tests, there is also a default waiting period of 3 days. After you register your package (and a PR is submitted to JuliaRegistries/General), you have to wait that much for your package to be automatically merged.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 7, 2020, 12:42am UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/7 "2020-06-07T00:42:12Z")

</div>

Have you checked [the relevant section of the manual](https://julialang.github.io/Pkg.jl/v1/creating-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:** [June 7, 2020, 2:13pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/8 "2020-06-07T14:13:16Z")

</div>

Please do not double-post (cf [Has anyone used Yao.jl for creating their own Julia package?](https://discourse.julialang.org/t/has-anyone-used-yao-jl-for-creating-their-own-julia-package/40882)).

Also, it is unclear if you want this question answered, or if you are just plugging that forum (which doesn’t appear to have a lot of activity for Julia, and may not be the ideal venue for Julia-specific questions).

---

<div class="post-metadata">

**Author:** ![rop11](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rop11](https://discourse.julialang.org/u/rop11)\
**Post date:** [June 12, 2020, 12:33pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/9 "2020-06-12T12:33:43Z")

</div>

I want the answer to question.

---

<div class="post-metadata">

**Author:** ![rop11](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rop11](https://discourse.julialang.org/u/rop11)\
**Post date:** [June 12, 2020, 12:35pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/10 "2020-06-12T12:35:07Z")

</div>

Yes, I have. But it’s kind of generic post.

---

<div class="post-metadata">

**Author:** ![sairus7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sairus7/32/10816_2.png) [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Post date:** [June 12, 2020, 1:03pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/11 "2020-06-12T13:03:16Z")

</div>

Package development in 1 hour:

[![](https://global.discourse-cdn.com/julialang/original/3X/a/9/a9eed041bdd2be4339d3e6dd3961b86bdc1511f3.jpeg "Developing Julia Packages") ](https://www.youtube.com/watch?v=QVmU29rCjaA)

In 4 minutes:

[![](https://global.discourse-cdn.com/julialang/original/3X/0/a/0a13feab3fe29a620fb9c07006ec84322ca4220b.jpeg "Why Julia - Package Development in Under 4 Minutes") ](https://www.youtube.com/watch?v=vVywlAgyedI)

---

<div class="post-metadata">

**Author:** ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)\
**Post date:** [June 14, 2020, 7:53pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/12 "2020-06-14T19:53:13Z")

</div>

If 1 hour is too much and 4 minutes is too little, you can do it in 10 minutes too:

> [@Make your Julia package in 10 minutes](https://discourse.julialang.org/t/make-your-julia-package-in-10-minutes/41368):
>
> I built my blog some time ago using [Franklin.jl](https://franklinjl.org/) and Bootstrap, and I was just waiting for the suitable blogpost material. It’s a common question here how to make your own package, so I decided to write a post about it. Here it is:

---

<div class="post-metadata">

**Author:** ![rop11](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rop11](https://discourse.julialang.org/u/rop11)\
**Post date:** [June 18, 2020, 10:19am UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/13 "2020-06-18T10:19:13Z")

</div>

Thanks. I’ll read it and let you know my feedback.

---

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [February 2, 2021, 7:58am UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/15 "2021-02-02T07:58:35Z")

</div>

A lot of the answers here and elsewhere concern building a package from scratch. In my case, I have basically built a beta of my package and uploaded it to Github. However, the package has none of the “structure” of a package (e.g. the `.toml` files and package metadata), and I would like to create these files and add my existing code to the package registry _without_ creating a new Github repository, if possible.

**How can I “convert” an existing project into a registered package while working within the same Github repository?**

Specifically, what I currently have in the root directory is a main `Foo.jl` file that defines a bunch of functions, a `readme.md`, and a bunch of example code and graphs in subdirectories.

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [February 2, 2021, 9:06am UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/16 "2021-02-02T09:06:00Z")

</div>

Something along these lines should work:

- Create a `src/` folder. Move your `Foo.jl` there. (Note that the name of this file fixes the package name to “Foo”.).
- Make sure that the `Foo.jl` file defines a module `Foo` and exports all the functions that your package should export.
- In the root of your repo, start `julia --project=.` and `] add SomePackages` all the dependencies of your package. This will create a `Project.toml` and `Manifest.toml`. As a starting point, `] add` all the packages that you are `using` in your `Foo.jl`.
- Edit the top of the `Project.toml` to specify a version etc., see [here](https://github.com/crstnbr/StableDQMC.jl/blob/master/Project.toml) for an example.
- Add the `Manifest.toml` to your `.gitignore` file. (In contrast to a project, for a package you don’t want to commit the `Manifest.toml`.)
- Create a `LICENSE` file. (For example something [like this](https://github.com/crstnbr/StableDQMC.jl/blob/master/LICENSE))

That’s the “mandatory” part. You should now have a valid package. But of course you should also add tests in a `test/runtests.jl` and documentation etc. For your example code (i.e. scripts) you could create a `examples/` subdirectory which you make a project by (within this directory) starting Julia as `julia --project=.` and adding the dependencies via `] add` (your scripts may depend on more packages than those required for “Foo” to work). Here, you keep both TOML files such that a user can `] instantiate` the precise versions of all packages that you used when creating you examples.

Hope this helps. (I might have forgotten 1 or 2 things but people will probably point this out 😃 )

---

<div class="post-metadata">

**Author:** ![zamk](https://avatars.discourse-cdn.com/v4/letter/z/ecd19e/32.png) [@zamk](https://discourse.julialang.org/u/zamk)\
**Post date:** [February 2, 2021, 9:29am UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/17 "2021-02-02T09:29:49Z")

</div>

Although it is somewhat directed to scientific projects, I found [DrWatson.jl](https://juliadynamics.github.io/DrWatson.jl/stable/) to be quite useful for package development.

---

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [February 2, 2021, 11:52pm UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/18 "2021-02-02T23:52:03Z")

</div>

Thank you!

When adding dependencies, should I list just those that are needed for the module’s core functionality, or any that are used anywhere in the project? For instance, in several of my example files I use `Plots`.

Or is there a way to annotate these different degrees of dependency?

Edit: Also, how do I add the module to my own Julia path before it has been registered?

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 3, 2021, 2:07am UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/19 "2021-02-03T02:07:22Z")

</div>

> [@maxkapur](#):
>
> When adding dependencies, should I list just those that are needed for the module’s core functionality, or any that are used anywhere in the project?

Just the ones needed for the module’s core functionality. In the `examples` folder of my packages I have another environment (this is, another `Project.toml` and `Manifest.toml`) with all the packages needed by the examples themselves.

> [@maxkapur](#):
>
> Also, how do I add the module to my own Julia path before it has been registered?

This is important for creating the environment (i.e., `.toml` files) of the `examples` folder, as often your examples will depend on your package. What I do is to:

```julia
julia> import Pkg
julia> Pkg.activate(".")
julia> Pkg.dev("..")

```

inside the `examples` folder. So you are saying to your examples that they depend on the package which they are themselves inside.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [February 3, 2021, 6:47am UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/20 "2021-02-03T06:47:53Z")

</div>

> [@carstenbauer](#):
>
> Edit the top of the `Project.toml` to specify a version etc., see [here](https://github.com/crstnbr/StableDQMC.jl/blob/master/Project.toml) for an example.

But you must not copy the `uuid` from somewhere else. Create a new one with

```julia
using UUIDs
uuid4()

```

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 3, 2021, 7:04am UTC](https://discourse.julialang.org/t/what-are-the-steps-to-create-your-own-package-in-julia/40877/21 "2021-02-03T07:04:16Z")

</div>

I recently wrote a guide A to Z to package development… this should answer the questions in this thread: [11 - Developing Julia packages - Julia language: a concise tutorial](https://syl1.gitbook.io/julia-language-a-concise-tutorial/language-core/11-developing-julia-packages)

It is not the _only_ way to create and publish a package, but it works 😉
