# Look up UUID of package by name in the General registry

**URL:** https://discourse.julialang.org/t/look-up-uuid-of-package-by-name-in-the-general-registry/52369
**Category:** General Usage
**Tags:** question
**Created:** [December 25, 2020, 11:55am UTC](https://discourse.julialang.org/t/look-up-uuid-of-package-by-name-in-the-general-registry/52369 "2020-12-25T11:55:16Z")
**Posts on this page:** 6
**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: [December 25, 2020, 11:55am UTC](https://discourse.julialang.org/t/look-up-uuid-of-package-by-name-in-the-general-registry/52369/1 "2020-12-25T11:55:16Z")

</div>

How can I look up UUID of a package by name in the General registry (or return `nothing` if there is no such package?)

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [December 25, 2020, 1:45pm UTC](https://discourse.julialang.org/t/look-up-uuid-of-package-by-name-in-the-general-registry/52369/2 "2020-12-25T13:45:48Z")

</div>

```julia
julia> import TOML

julia> function lookup(name)
           # Look up Registry.toml files in depots
           tomlfiles = String[]
           for d in DEPOT_PATH
               regs = joinpath(d, "registries")
               if isdir(regs)
                   for r in readdir(regs)
                       toml = joinpath(regs, r, "Registry.toml")
                       if isfile(toml)
                           push!(tomlfiles, toml)
                       end
                   end
               end
           end
           
           # Look up uuids in toml files
           uuids = Base.UUID[]
           for f in tomlfiles
               toml = TOML.parsefile(f)
               if haskey(toml, "packages")
                   for (k, v) in toml["packages"]
                       if v["name"] == name
                           push!(uuids, Base.UUID(k))
                       end
                   end
               end
           end
           return uuids
       end
lookup (generic function with 1 method)

julia> lookup("Literate")
1-element Vector{Base.UUID}:
 UUID("98b081ad-f1c9-55d3-8b20-4c87d4299306")

```

---

<div class="post-metadata">

### Author: ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)
#### Post date: [December 25, 2020, 1:52pm UTC](https://discourse.julialang.org/t/look-up-uuid-of-package-by-name-in-the-general-registry/52369/3 "2020-12-25T13:52:27Z")

</div>

I think the question was opposite, how to do something like this:

```julia
julia> lookup("Literate")
"98b081ad-f1c9-55d3-8b20-4c87d4299306"

```

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [December 25, 2020, 2:04pm UTC](https://discourse.julialang.org/t/look-up-uuid-of-package-by-name-in-the-general-registry/52369/4 "2020-12-25T14:04:14Z")

</div>

Of course, I inverted the condition somehow. Fixed now.

---

<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 25, 2020, 4:11pm UTC](https://discourse.julialang.org/t/look-up-uuid-of-package-by-name-in-the-general-registry/52369/5 "2020-12-25T16:11:02Z")

</div>

Thanks for the nice solution.

Incidentally, I may need to adjust my thinking a bit. I was somehow implicitly assuming that this data is stored in a data structure handled by `Pkg`, which consequently may/should provide an API to extract it.

But in fact, this data is in a TOML file, and when I ask Pkg to do something similar, it parses the same TOML file — I can access this data directly. I have to admit that this did not occur to me.

Incidentally, is the registry TOML format documented somewhere? It is pretty self-explanatory, just being curious.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [December 25, 2020, 10:08pm UTC](https://discourse.julialang.org/t/look-up-uuid-of-package-by-name-in-the-general-registry/52369/6 "2020-12-25T22:08:42Z")

</div>

On Pkg master (might not be on Julia master) you can do:

```julia
julia> reg = Pkg.Registry.RegistryInstance(joinpath(homedir(), ".julia/registries/General"))
Registry: "General" at "/Users/kristoffercarlsson/.julia/registries/General":
  uuid: 23338594-aafe-5451-b93e-139f81909106
  repo: https://github.com/JuliaRegistries/General.git
  git-tree-sha1: c3b2b9b7518793da48dd6cf56a9337be3dd5195f
  packages: 4754

julia> Pkg.Registry.uuids_from_name(reg, "Literate")
1-element Vector{Base.UUID}:
 UUID("98b081ad-f1c9-55d3-8b20-4c87d4299306")

```

(of course, these are internal functions).
