# Is there a function to query what has been imported into the current module/namespace from \`export\` statements in other modules?

**URL:** https://discourse.julialang.org/t/is-there-a-function-to-query-what-has-been-imported-into-the-current-module-namespace-from-export-statements-in-other-modules/122218
**Category:** New to Julia
**Tags:** question
**Created:** [November 4, 2024, 11:23am UTC](https://discourse.julialang.org/t/is-there-a-function-to-query-what-has-been-imported-into-the-current-module-namespace-from-export-statements-in-other-modules/122218 "2024-11-04T11:23:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![world-peace](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@world-peace](https://discourse.julialang.org/u/world-peace)
#### Post date: [November 4, 2024, 11:23am UTC](https://discourse.julialang.org/t/is-there-a-function-to-query-what-has-been-imported-into-the-current-module-namespace-from-export-statements-in-other-modules/122218/1 "2024-11-04T11:23:38Z")

</div>

Here’s a couple of things I have tried:

```julia
julia> using Dates

julia> names(Main)
6-element Vector{Symbol}:
 :Base
 :Core
 :Main
 :SRC
 :skipInit
 :updateLoadPath

```

This didn’t print anything relating to the `Dates` module, or any exported names from the `Dates` module.

I am looking for a function which shows what names/symbols are available in the current module, which happens to be `Main` here.

After running `using Dates`, I would expect such a function to print

```julia
Dates, Day, Hour, Minute, Second, etc

```

but _not_

```julia
CompoundPeriod

```

because if I understand correctly, that name is _not_ exported by the `Dates` module.

I could be wrong about this last point.

* * *

```julia
julia> filter(name->occursin("eriod", String(name)), names(Main.Dates))
3-element Vector{Symbol}:
 :DatePeriod
 :Period
 :TimePeriod

```

This does not print `CompoundPeriod`. It seems like this might work as expected, but it’s a lot to type to query this infomation.

---

<div class="post-metadata">

### Author: ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)
#### Post date: [November 4, 2024, 2:17pm UTC](https://discourse.julialang.org/t/is-there-a-function-to-query-what-has-been-imported-into-the-current-module-namespace-from-export-statements-in-other-modules/122218/3 "2024-11-04T14:17:39Z")

</div>

It’s not in 1.11, but you will get it in 1.12, with a named `usings` argument to `names`. I.e. you can then do `names(Main, usings=true)`.

> <https://github.com/JuliaLang/julia/pull/54609>
>
> This commit makes it possible for \`names\` to return \`using\`-ed names as well:
> \`…\`\`julia
> julia\> using Base: @assume\_effects
> 
> julia\> Symbol("@assume\_effects") in names(@\_\_MODULE\_\_; usings=true)
> true
> \`\`\`
> 
> Currently, to find all names available in a module \`A\`, the following steps are needed:
> 1. Use \`names(A; all=true, imported=true)\` to get the names defined by \`A\` and the names explicitly \`import\`ed by \`A\`.
> 2. Use \`jl\_module\_usings(A)\` to get the list of modules \`A\` has \`using\`-ed and then use \`names()\` to get the names \`export\`ed by those modules.
> 
> This method is implemented in e.g. REPL completions, but it has a problem: it could not get the names explicitly \`using\`-ed by \`using B: ...\` (#36529, #40356, JuliaDebug/Infiltrator.jl#106, etc.).
> 
> This commit adds a new keyword argument \`usings::Bool=false\` to \`names(A; ...)\`, which, when \`usings=true\` is specified, returns all names introduced by \`using\` in \`A\`.
> In other words, \`usings=true\` not only returns explicitly \`using\`-ed names but also incorporates step 2 above into the implementation of \`names\`.
> 
> By using this new option, we can now use
> \`names(A; all=true, imported=true, usings=true)\` to know all names available in \`A\`, without implementing the two-fold steps on application side.
> As example application, this new feature will be used to simplify and enhance the implementation of REPL completions.
> 
> \- fixes #36529

> <https://github.com/JuliaLang/julia/pull/54659>
>
> This commit refines the keyword arguments that \`names\` can accept, allowing for …more specific exclusions, such as excluding deprecated names or implicitly \`using\`-ed names.
> For the new behavior of \`names\`, please refer to the following docstring:
> 
> \> names(x::Module; non\_public::Bool=false, imported::Bool=false,
> \> usings\_explicit::Bool=false, usings\_implicit::Bool=false,
> \> generated::Bool=false, deprecated::Bool=false,
> \> \[usings::Bool=false\], \[all::Bool=false\]) -\> Vector{Symbol}
> \>
> \> Return a vector of the sorted names of module \`x\`.
> \>
> \> By default, only public names defined within \`x\` are returned.
> \>
> \> By specifying the following keyword arguments, additional names can be included:
> \> - \`non\_public=true\`: includes names defined within \`x\` that are not public.
> \> - \`imported=true\`: includes names explicitly imported from other modules via \`import\` statements.
> \> - \`usings\_explicit=true\`: includes names explicitly imported from other modules via \`using\` statements.
> \> - \`usings\_implicit=true\`: includes names implicitly imported from other modules via \`using\` statements
> (i.e., names exported by modules that \`x\` has \`using\`-ed).
> \> - \`generated=true\`: includes names generated by the compiler frontend (specifically those starting with \`#\`).
> \> - \`deprecated=true\`: includes deprecated names.
> 
> Note that the previously existing options (\`all\` and \`usings\`) are retained as alias arguments, ensuring that the previous behavior of \`names\` is preserved.
> \> Additionally, the following keyword arguments can be used as aliases to conveniently specify these options:
> \> - \`usings::Bool=true\`: a shortcut to set both \`usings\_explicit\` and \`usings\_implicit\` to \`true\`.
> \> - \`all::Bool=true\`: a shortcut to set \`non\_public\`, \`generated\`, and \`deprecated\` to \`true\`.
> 
> By utilizing these newly and accurately defined options, the implementation of downstream applications like REPL completions can be simplified.

---

<div class="post-metadata">

### Author: ![world-peace](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@world-peace](https://discourse.julialang.org/u/world-peace)
#### Post date: [November 4, 2024, 3:40pm UTC](https://discourse.julialang.org/t/is-there-a-function-to-query-what-has-been-imported-into-the-current-module-namespace-from-export-statements-in-other-modules/122218/4 "2024-11-04T15:40:47Z")

</div>

Ok thank you. Useful to know about this.

---

<div class="post-metadata">

### Author: ![tecosaur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tecosaur/32/23206_2.png) [@tecosaur](https://discourse.julialang.org/u/tecosaur)
#### Post date: [November 5, 2024, 3:14am UTC](https://discourse.julialang.org/t/is-there-a-function-to-query-what-has-been-imported-into-the-current-module-namespace-from-export-statements-in-other-modules/122218/5 "2024-11-05T03:14:18Z")

</div>

🤔 I could probably add a specialisation to `about(Main)` in About.jl
