An example of a very minimal Python package.
You can directly install this minimal package from its repository using pip.
Let's illustrate this using a Python virtual environment:
First create a virtual environment venv and activate it:
python3 -m venv venv
. venv/bin/activatethen install this package in it:
python3 -m pip install git+https://github.com/jennan/my_little_packageNote: You can install a specific version using the corresponding tag, e.g. to install version 0.1.3
python3 -m pip install git+https://github.com/jennan/my_little_package@v0.1.3We can now use import it and use it:
$ python3
>>> from my_little_package.talk import greeting
>>> greeting("Pinkie Pie")
Hello Pinkie Pie!The package also provides a command line tool mlp that we can make use of:
mlp # issue an error as it is missing a parameter
mlp -h # display help message
mlp ApplejackDuring development, it is useful to install the local clone of the repository in development mode:
git clone https://github.com/jennan/my_little_package.git
cd my_little_package
python3 -m venv venv
. venv/bin/activate
python3 -m pip install -e .In development mode (or editable installs), any change to the source files is readily available in the virtual environment without reinstalling the package.
This package also defines additional dependencies for development, for example the formatter and linter ruff.
To install these additional dependencies, add the [dev] statement to the installation command:
python3 -m pip install -e .[dev]Now we can use ruff to format our code and keep it nice and tidy:
ruff src/
We can also run the tests defined in the tests folder using pytest:
pytest