BeginPackage
✖
BeginPackage
Details

- BeginPackage is typically used at the beginning of a Wolfram Language package.
- BeginPackage resets the values of both $Context and $ContextPath.
- The interpretation of symbol names depends on context. BeginPackage thus affects the parsing of input expressions.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Commands to define a simple package:

https://wolfram.com/xid/0rs93ewhe-dvbuxu
The context for symbol creation has been changed to square`:

https://wolfram.com/xid/0rs93ewhe-sbw2h

The context path for symbol lookup includes square`:

https://wolfram.com/xid/0rs93ewhe-dtgtny

Here are the commands defining the function in the package:

https://wolfram.com/xid/0rs93ewhe-dphcwo

https://wolfram.com/xid/0rs93ewhe-cbhno5
Restore the context, but leave square` on the context path for symbol lookup:

https://wolfram.com/xid/0rs93ewhe-if3el5
Since EndPackage leaves square`square on the context path, the function defined is visible:

https://wolfram.com/xid/0rs93ewhe-b5wc41

https://wolfram.com/xid/0rs93ewhe-cnd08v

Scope (1)Survey of the scope of standard use cases
Use BeginPackage and EndPackage to start and end a package in a file:

https://wolfram.com/xid/0rs93ewhe-mzdi2z
The package can be loaded with Get:

https://wolfram.com/xid/0rs93ewhe-f9dwb4
Once loaded, the definitions work:

https://wolfram.com/xid/0rs93ewhe-fe7xaf

Properties & Relations (3)Properties of the function, and connections to other functions
BeginPackage["cont`"] sets $Context to "cont`":

https://wolfram.com/xid/0rs93ewhe-7m7isf

EndPackage restores $Context to its value before the matching BeginPackage:

https://wolfram.com/xid/0rs93ewhe-cly9h7

BeginPackage["cont`"] sets $ContextPath to {"cont`","System`"}:

https://wolfram.com/xid/0rs93ewhe-p3oqhg

EndPackage restores $ContextPath to its value before BeginPackage with "cont`" prepended:

https://wolfram.com/xid/0rs93ewhe-0ji1c8

BeginPackage does not alter the value of $ContextAliases:

https://wolfram.com/xid/0rs93ewhe-c4es0g

EndPackage restores $ContextAliases to its value before the matching BeginPackage:

https://wolfram.com/xid/0rs93ewhe-8614wm

Wolfram Research (1988), BeginPackage, Wolfram Language function, https://reference.wolfram.com/language/ref/BeginPackage.html.
Text
Wolfram Research (1988), BeginPackage, Wolfram Language function, https://reference.wolfram.com/language/ref/BeginPackage.html.
Wolfram Research (1988), BeginPackage, Wolfram Language function, https://reference.wolfram.com/language/ref/BeginPackage.html.
CMS
Wolfram Language. 1988. "BeginPackage." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BeginPackage.html.
Wolfram Language. 1988. "BeginPackage." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BeginPackage.html.
APA
Wolfram Language. (1988). BeginPackage. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BeginPackage.html
Wolfram Language. (1988). BeginPackage. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BeginPackage.html
BibTeX
@misc{reference.wolfram_2025_beginpackage, author="Wolfram Research", title="{BeginPackage}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/BeginPackage.html}", note=[Accessed: 16-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_beginpackage, organization={Wolfram Research}, title={BeginPackage}, year={1988}, url={https://reference.wolfram.com/language/ref/BeginPackage.html}, note=[Accessed: 16-April-2025
]}