# How to get ALL variable names currently accessible

**URL:** <https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 15, 2024, 5:39pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839 "2024-01-15T17:39:45Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [January 15, 2024, 5:39pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/1 "2024-01-15T17:39:45Z")

</div>

I know about `Base.names`, however it ignores all the variables which are imported via `using`.

Is there a function which also includes these?

Or is there a way to tell whether a module was imported like `using DataFrames`? Then I could apply `names` once again to get the exported names of these imported packages and add them

EDIT: I just realized that when using `using DataFrames`, then `:DataFrames` itself is also not part of `names`.

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [January 15, 2024, 6:24pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/2 "2024-01-15T18:24:01Z")

</div>

I found one workaround

```julia
modules(m::Module) = ccall(:jl_module_usings, Any, (Any,), m)

```

this will list all Modules which were imported via `using THatModule`

EDIT: then you can call `names` on those modules

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 15, 2024, 6:51pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/3 "2024-01-15T18:51:51Z")

</div>

Would this help ([code](https://stackoverflow.com/a/71986006/14071775) by @bkamins):  
`println(Main.varinfo(@ __MODULE__ ; all=true, imported=true))`

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 15, 2024, 7:00pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/4 "2024-01-15T19:00:09Z")

</div>

> [@schlichtanders](#):
>
> I know about `Base.names`, however it ignores all the variables which are imported via `using`.

Just pass [`imported=true` to `names`](https://docs.julialang.org/en/v1/base/base/#Base.names).

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [January 15, 2024, 7:57pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/5 "2024-01-15T19:57:20Z")

</div>

varinfo and names both do not work as described. They just don’t list the names

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 15, 2024, 8:00pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/6 "2024-01-15T20:00:09Z")

</div>

> [@schlichtanders](#):
>
> varinfo and names both do not work as described. They just don’t list the names

What’s wrong with, for example:

```julia
julia> import Statistics

julia> names(Main, imported=true)
8-element Vector{Symbol}:
 :Base
 :Core
 :InteractiveUtils
 :Main
 :Pkg
 :Statistics
 :eval
 :include

```

(Note that `names` itself does not _print_ anything — it _returns_ an array of the symbols. When you evaluate this in the REPL, it calls `display(...)` on the return value, which prints the text output as above. You can also call `display` or `print` or some other I/O function yourself on the return value.)

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [January 15, 2024, 8:52pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/7 "2024-01-15T20:52:26Z")

</div>

you are using `import Statistics`, try it with `using Statistics`.  
It is really surprising

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 15, 2024, 11:38pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/8 "2024-01-15T23:38:33Z")

</div>

From the docs:

> If `imported` is true, then names explicitly imported from other modules are also included.

```julia
julia> import Statistics: mean

julia> names(Main, imported=true)
8-element Vector{Symbol}:
 :Base
 :Core
 :InteractiveUtils
 :Main
 :Pkg
 :eval
 :include
 :mean

```

That is, you have to `import` the name explicitly, not just be `using` it.

So, I agree, this is not what you want. The REPLCompletions module [seems to call the internal function `jl_module_usings`](https://github.com/JuliaLang/julia/blob/89710bf8a1914e22fe61e4e087f5ff5e97a32f02/stdlib/REPL/src/REPLCompletions.jl#L184) in order to also fetch symbols imported by `using`, as you noted above.

You can call the REPLCompletions module, I guess, but this also relies on undocumented internals:

```julia
using REPL: REPLCompletions
REPLCompletions.complete_symbol(nothing, "", (mod, s) -> true, Main)

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [January 16, 2024, 6:18am UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/9 "2024-01-16T06:18:07Z")

</div>

> [@schlichtanders](#):
>
> you are using `import Statistics`, try it with `using Statistics`.

`names` treats `Main` specially so it does show up:

```julia
julia> using Statistics

julia> names(Main; all=true,imported=true)
8-element Vector{Symbol}:
 Symbol("##meta#58")
 :Base
 :Core
 :InteractiveUtils
 :Main
 :Statistics
 :eval
 :include

```

Here’s an example for a different module:

```julia
julia> module A using Statistics end; # avoid Main because treated specially

julia> names(A; all=true,imported=true)
5-element Vector{Symbol}:
 Symbol("#eval")
 Symbol("#include")
 :A
 :eval
 :include

julia> module A import Statistics end; # avoid Main because treated specially
WARNING: replacing module A.

julia> names(A; all=true,imported=true)
6-element Vector{Symbol}:
 Symbol("#eval")
 Symbol("#include")
 :A
 :Statistics
 :eval
 :include

julia> module A using Statistics: Statistics, mean; s = mean(1:5) + Statistics.var(1:3) end; # avoid Main because treated specially
WARNING: replacing module A.

julia> names(A; all=true, imported=true)
6-element Vector{Symbol}:
 Symbol("#eval")
 Symbol("#include")
 :A
 :eval
 :include
 :s

julia> module A import Statistics: Statistics, mean; s = mean(1:5) + Statistics.var(1:3) end; # avoid Main because treated specially
WARNING: replacing module A.

julia> names(A; all=true, imported=true)
8-element Vector{Symbol}:
 Symbol("#eval")
 Symbol("#include")
 :A
 :Statistics
 :eval
 :include
 :mean
 :s

```

> [@stevengj](#):
>
> That is, you have to `import` the name explicitly, not just be `using` it.

Is there a good reason for this? I’m surprised that names imported by `import` and `using` are even delineated so strictly because colon-specified names and the module names in bare `using`/`import` statements can’t be shadowed like the `export` list names accessed by bare `using` statements. I’d consider the former to be essentially explicit imports, and like schlictsanders I think they should be reported by the `imported=true` option, especially the modules in bare `using` statements because I’d need to use `names` to check their export lists the most. I’d also prefer if the `imported=true` option reported any names from bare `using` statements after they were accessed and thus made unshadowable, but those imports don’t seem explicit in any sense.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 16, 2024, 1:15pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/10 "2024-01-16T13:15:00Z")

</div>

> [@Benny](#):
>
> I’m surprised that names imported by `import` and `using` are even delineated so strictly

`import`ed names are treated very differently for [method definitions](https://docs.julialang.org/en/v1/manual/methods/#Redefining-Methods).

I guess the basic issue here is that people mostly use `names` to obtain the API defined in a module, and it’s rare that they want to pull in 1000+ additional symbols defined in `Base` etcetera. But it would be nice to have that option.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [January 16, 2024, 5:13pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/11 "2024-01-16T17:13:11Z")

</div>

> [@stevengj](#):
>
> `import`ed names are treated very differently for [method definitions](https://docs.julialang.org/en/v1/manual/methods/#Redefining-Methods).

That link doesn’t involve imports, but do you mean how function names from `import` statements don’t need module name qualification to add methods?

> [@stevengj](#):
>
> it’s rare that they want to pull in 1000+ additional symbols defined in `Base`

That’s true, I’d probably just want to check the already accessed, implicitly imported symbols at the most. Still, I’d think `using Base` itself should let `Base` show up, and `using Base: +, ^` should let `+` and `^` show up, just like if I used the `import` keyword. Those don’t risk unintended bloat. Those 1000+ symbols can be checked with `names(Base)`, so if `names(A;imported=true)` reported `Base`, that’ll be enough for me to know what to check further. Or perhaps bare `using Base` should be reported under another keyword option for that purpose, it’s not like I need to check `names(+)`.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [January 16, 2024, 10:35pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/12 "2024-01-16T22:35:34Z")

</div>

Getting names from “used” modules.

```julia

module M1
    f1(x) = x
    f2(x) = 2x
    export f2
end

module M3
    f3(x) = 3x
    export f3
end

module M2
using ..M1, ..M3
    mods = ccall(:jl_module_usings, Any, (Any,), @ __MODULE__ )::Vector
    setdiff!(mods, [Base, Core])
    mnames = [string(m) => names(m) for m in mods]
    @show mnames
end 

julia> 
mnames = ["Main.M3" => [:M3, :f3], "Main.M1" => [:M1, :f2]]

```

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [January 24, 2024, 10:16pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/13 "2024-01-24T22:16:41Z")

</div>

anybody knows, is there any way to get also variable names imported like following?

```julia
using Unitful: Na 

```

`names` wouldn’t list them, and `jl_module_usings` only list modules.

---

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [October 23, 2025, 12:01pm UTC](https://discourse.julialang.org/t/how-to-get-all-variable-names-currently-accessible/108839/14 "2025-10-23T12:01:01Z")

</div>

As of 1.12: `names(Module, all=true, imported=true, usings=true)`
