<jupyter_start><jupyter_text>Python Packages **Learning Objective:** Learn what a Python package and how to import it.  Built-ins The Python programming language offers a very minimal set of objects and functions. These are called **built-ins**<jupyter_code>dir(__builtins__)<jupyter_output><empty_output><jupyter_text>All other capabilities are shipped as **packages** that have to be **imported** before you can use them.  Packages * A Python **package** is one of two things:  - A single file with a `.py` (pure Python) extension or `.so` extension (compiled).  - A directory of files with `.py`/`.so` extensions and `__init__.py` files.* To use a package you must first **import** it.* The files within packages are called **modules**.* Once you import a package, you can usually see what files it comes from using the `__file__` attribute.Let's import the `functools` package and see what file it is coming from:<jupyter_code>import functools
functools.__file__<jupyter_output><empty_output><jupyter_text>You can also use `from` to import specific names from a package:<jupyter_code>from math import cos
cos(1.0)<jupyter_output><empty_output><jupyter_text>Packages and import statements can also be nested:<jupyter_code>from numpy.random import rand
rand()<jupyter_output><empty_output><jupyter_text>You can also use the `as` keyword to change the name of a package. For example the `numpy` package is usually imported under the name `np`:<jupyter_code>import numpy as np
np.random.rand()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09192383453709783, 'fraction_numerical': 0.0013131976362442547, 'mean_word_length': 6.121495327102804, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '387914', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 455, 'n_tokens_neox': 445, 'n_words': 183, 'path': 'Content/Programming/PythonPackages.ipynb', 'repo_name': 'calpolydatascience/ds4e', 'size': '1523'}