PackageExported[symbol]
makes symbol an exported symbol from the current package.
PackageExported[{sym1,sym2,…}]
exports multiple symbols.
PackageExported
PackageExported[symbol]
makes symbol an exported symbol from the current package.
PackageExported[{sym1,sym2,…}]
exports multiple symbols.
Details
- PackageExported works only in files that use the Structured Package Format (SPF).
- Symbols named in PackageExported statements are created in the package's main context, and are visible to all files within a package as well as to users who load the package.
- You can specify the symbols to export as symbols or strings. Symbols will not be evaluated.
- PackageExported statements can be placed wherever you like in your package: close to where the definitions for the symbol appear, collected at the top of each file, collected into one file of your package, etc.
- PackageExported statements are read in a special way and must appear in files on a line of their own.
- Any symbol not named in a PackageExported or PackageScoped statement is private to the file in which it appears.
Examples
Basic Examples (3)
The SPFExample directory in ExampleData contains an extremely simple package in the Structured Package Format (SPF) style. This is the one-line contents of the init.wl file:
PackageInitialize["SPFExample`"]
When the init.wl file loads, PackageInitialize gathers up the surrounding source files and loads them to become the SPFExample` package.
This is the contents of the PackageFile1.wl file:
PackageExported[Func1]
Func1[x_] := x+1
PackageScoped[utilFunc]
utilFunc[n_] := n^2
This is the contents of the PackageFile2.wl file:
PackageExported[Func2]
Func2[x_] := utilFunc[x]
Because the symbols Func1 and Func2 are named in PackageExported statements, they will be visible in a user's session after the package loads.
This example package is not in a directory that is part of the package search path. First, add it to $Path so that it can be found via a context name:
AppendTo[$Path, FileNameJoin[$InstallationDirectory, "Documentation", "English", "System", "ExampleData"]];Now load the package in the usual way:
Needs["SPFExample`"]The Func1 function is visible in the session:
Func1[2]PackageExported is only meaningful when called from a file of code that is part of a package, not during interactive input:
PackageExported[SomeSymbol]PackageExported statements must appear alone on their own line. Create a temporary file containing an improper PackageExported statement and call PackageInitialize to create a package out of it:
tempdir = CreateDirectory[];
tempfile = FileNameJoin[tempdir, "BadPackageExport.wl"];
WriteString[tempfile, "PackageExported[Foo] + 1"];
Close[tempfile];
PackageInitialize["TempContext`", tempdir];This example is similar to the previous one, demonstrating that you cannot "program" with PackageExport—it must be written verbatim in the file:
tempdir = CreateDirectory[];
tempfile = FileNameJoin[tempdir, "BadPackageExport.wl"];
WriteString[tempfile, "PackageExported /@ {Foo, Bar}"];
Close[tempfile];
PackageInitialize["TempContext`", tempdir];See Also
Tech Notes
Related Guides
History
Text
Wolfram Research (2026), PackageExported, Wolfram Language function, https://reference.wolfram.com/language/ref/PackageExported.html.
CMS
Wolfram Language. 2026. "PackageExported." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/PackageExported.html.
APA
Wolfram Language. (2026). PackageExported. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PackageExported.html
BibTeX
@misc{reference.wolfram_2026_packageexported, author="Wolfram Research", title="{PackageExported}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/PackageExported.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_packageexported, organization={Wolfram Research}, title={PackageExported}, year={2026}, url={https://reference.wolfram.com/language/ref/PackageExported.html}, note=[Accessed: 12-June-2026]}