Python Library Template (PyLibTemplate)
pylibtemplate (short for 'Python Library Template') is a Python library that
generates git repository templates for building Python libraries that are
suitable for publication on PyPI.
Visit the pylibtemplate website
for a web version of the installation instructions, the reference guide, and the
examples archive.
The source code can be found in the pylibtemplate GitHub
repository.
Table of contents
- Instructions for installing and uninstalling
pylibtemplate - How to create a Python library using
pylibtemplate- Create a new empty GitHub repository for your new Python library
- Create a new GitHub gist for your new Python library
- Create a new GitHub token for your new Python library
- Create a new GitHub environment for your new Python library
- Configure GitHub Pages for your new Python library
- Create local
gitrepository template usingpylibtemplate - Add GitHub remote repository to local
gitrepository - Modify local repository files
Instructions for installing and uninstalling pylibtemplate
Installing pylibtemplate
For all installation scenarios, first open up the appropriate command line interface. On Unix-based systems, you could open e.g. a terminal. On Windows systems you could open e.g. an Anaconda Prompt as an administrator.
Installing pylibtemplate using pip
Before installing pylibtemplate, make sure that you have activated the
(virtual) environment in which you intend to install said package. After which,
simply run the following command:
pip install pylibtemplate
The above command will install the latest stable version of pylibtemplate.
To install the latest development version from the main branch of the pylibtemplate GitHub repository, one must first clone the repository by running the following command:
git clone https://github.com/mrfitzpa/pylibtemplate.git
Next, change into the root of the cloned repository, and then run the following command:
pip install .
Note that you must include the period as well. The above command executes a
standard installation of pylibtemplate.
Optionally, for additional features in pylibtemplate, one can install
additional dependencies upon installing pylibtemplate. To install a subset of
additional dependencies (along with the standard installation), run the
following command from the root of the repository:
pip install .[<selector>]
where <selector> can be one of the following:
tests: to install the dependencies necessary for running unit tests;examples: to install the dependencies necessary for executing files stored in<root>/examples, where<root>is the root of the repository;docs: to install the dependencies necessary for documentation generation;all: to install all of the above optional dependencies.
Alternatively, one can run:
pip install pylibtemplate[<selector>]
elsewhere in order to install the latest stable version of pylibtemplate,
along with the subset of additional dependencies specified by <selector>.
Installing pylibtemplate using conda
To install pylibtemplate using the conda package manager, run the following
command:
conda install -c conda-forge pylibtemplate
The above command will install the latest stable version of pylibtemplate.
Uninstalling pylibtemplate
If pylibtemplate was installed using pip, then to uninstall, run the
following command:
pip uninstall pylibtemplate
If pylibtemplate was installed using conda, then to uninstall, run the
following command:
conda remove pylibtemplate
How to create a Python library using pylibtemplate
The following instructions assume that the reader understands completely the
purpose of each file in the pylibtemplate GitHub
repository, in relation to the
corresponding Python library pylibtemplate.
Create a new empty GitHub repository for your new Python library
Before generating your git repository template for building your new Python
library, several other actions need to be performed, the first of which is to
create a new empty public GitHub repository, which will serve as the remote
repository for your new Python library. The GitHub repository should share the
same name as your new Python library, as it would appear in a pip install
command. We will refer to the name of your new Python library as
<your_lib_name>.
Create a new GitHub gist for your new Python library
We need to create a new GitHub gist that will be used to record the code coverage from your unit tests. To create a new gist, first go to https://gist.github.com. Next, in the field containing the placeholder text "Gist description" write:
To store the code coverage of the `<your_lib_name>` library.
Next, in the field containing the placeholder text "Filename including extension...", write:
<your_lib_name>_coverage_badge.json
Next, in the field directly below --- where the gist contents are suppose to be written --- write:
{}
Next, click on the green down arrow button in the bottom right corner, select the "Create public gist" option, and then click the "Create public gist" button.
Upon creating the new gist, you will be redirected to a new page that presents
the gist. Copy or save somewhere the string of characters following the last /
in the URL of said page. This string of characters is the ID of the gist that
you just created. We will refer to the gist ID as <your_gist_id>.
Create a new GitHub token for your new Python library
Next, we need to create a new GitHub token with gist scope. To do this, first go to https://github.com/settings/tokens. Next, click on the button "Generate new token" and select the "Generate new token (classic)" option. Next, in the field directly below "Note", write:
To access the `<your_lib_name>` code coverage file.
Next, in the field directly below "Expiration", select whatever expiration date
that you prefer. Next, select the "gist" box amongst the options of scope. Next,
click on the "Generate token" button. Next, copy or save somewhere the personal
access token that appears on the current page. We will refer to the personal
access token as <your_access_token>. Next, go to the main page of the
<your_lib_name> GitHub repository. Next, click on "Settings", then "Secrets
and variables" in the side menu that appears, followed by "Actions" in the
sub-menu. Next, click on the "New repository secret" button. In the field
containing the placeholder text "YOUR_SECRET_NAME", write:
CODE_COVERAGE_SECRET
In the field directly below "Secret *", copy and paste <your_access_token>.
Create a new GitHub environment for your new Python library
In order to add your GitHub repository as a pending publisher on PyPI, you need
to create a specific GitHub environment for said repository. To do this, first
go to the main page of the <your_lib_name> GitHub repository. Next, click on
"Settings", then "Environments" in the side menu that appears. Next, click on
the "New environment" button. In the field directly below "Name *", write:
release
and then click on the "Configure environment" button.
Configure GitHub Pages for your new Python library
Next, we need to configure the GitHub Pages for you new Python library. To do
this, first go to the main page of the <your_lib_name> GitHub
repository. Next, click on "Settings", then "Pages" in the side menu that
appears. In the field directly below "Source", select "GitHub Actions".
Create local git repository template using pylibtemplate
Next, we need to create a local git repository template using
pylibtemplate. To do this, activate an environment in which pylibtemplate is
installed, and then execute the following Python code block:
import pylibtemplate
kwargs = {"lib_name_for_imports": \
<your_lib_name>,
"abbreviated_lib_name_for_docs": \
<your_abbreviated_lib_name_for_docs>,
"non_abbreviated_lib_name_for_docs": \
<your_non_abbreviated_lib_name_for_docs>,
"author": \
<author>,
"email": \
<email>,
"gist_id": \
<your_gist_id>,
"path_to_directory_to_contain_new_repo": \
<path_to_directory_to_contain_new_repo>}
pylibtemplate.generate_local_git_repo_template(**kwargs)
This code block will perform several actions: First, it will clone the git
commit of the pylibtemplate GitHub repository corresponding to the version of
pylibtemplate being used currently, in the directory at the patth
<path_to_directory_to_contain_new_repo>, i.e. the git clone command is
executed while the working directory is set temporarily to the path
path_to_directory_to_contain_new_repo; Next, it will rename the cloned
repository to <your_lib_name> such that the path to the cloned repository
becomes <path_to_directory_to_contain_new_repo>/<your_lib_name>; Next, all
instances of the string of characters "pylibtemplate" are replaced with
<your_lib_name>, be it in file contents, directory basenames, or file
basenames; Next, all instances of the string of characters "PyLibTemplate" are
replaced with <your_abbreviated_lib_name_for_docs>; Next, all instances of the
string of characters "Python Library Template" are replaced with
<your_non_abbreviated_lib_name_for_docs>; Next, all email address placeholders
(i.e. instances of the string of characters "matthew.rc.fitzpatrick@gmail.com")
are replaced with <email>; Next, all instances of the gist ID of
pylibtemplate are replaced with <your_gist_id>; Next, all author
placeholders (i.e. instances of the string of characters "Matthew Fitzpatrick")
are replaced with <author>; Next, all copyright statements are updated
according to the current year; And lastly, the following file is removed:
<local_repo_root>/docs/how_to_create_a_python_library_using_pylibtemplate.rst
where <local_repo_root> is the root of the local git repository, as well
as the following directory:
<local_repo_root>/.git
Instead of executing the above Python code block, one can achieve the same
result by running pylibtemplate as a command line too. To do this, activate an
environment in which pylibtemplate is installed, and then execute the
following command in the terminal:
pylibtemplate --lib_name_for_imports=<your_lib_name> --abbreviated_lib_name_for_docs=<your_abbreviated_lib_name_for_docs> --non_abbreviated_lib_name_for_docs=<your_non_abbreviated_lib_name_for_docs> --author=<author> --email=<email> --gist_id=<your_gist_id> --path_to_directory_to_contain_new_repo=<path_to_directory_to_contain_new_repo>
Add GitHub remote repository to local git repository
Once you have created your local git repository template, you should add to it
the GitHub repository that you created in the very first step above. To do this,
run the following commands in a terminal:
git init
git remote add origin https://github.com/<your_username>/<your_lib_name>.git
git branch -M main
git push -u origin main
where <your_username> is the name of the GitHub user that created the GitHub
repository.
Modify local repository files
Of course, now you must modify the local git repository files in order to
develop your new Python library.
The following files do not need to be modified under any circumstances:
<local_repo_root>/.coveragerc<local_repo_root>/tox.ini<local_repo_root>/docs/Makefile<local_repo_root>/docs/make.bat<local_repo_root>/docs/api.rst<local_repo_root>/docs/private_members_to_publish_to_docs.rst
The following files may need to be modified to reflect the appropriate license
should it differ from that of pylibtemplate:
<local_repo_root>/run_tests.sh<local_repo_root>/setup.py<local_repo_root>/LICENSE<local_repo_root>/docs/license.rst<local_repo_root>/docs/build_docs.py
The following files may need to be modified if a custom installation procecdure is required to run your new Python library's unit tests, that differs from the default installation procedure:
<local_repo_root>/.github/workflows/measure_code_coverage.yml<local_repo_root>/.github/workflows/test_library.yml<local_repo_root>/.github/workflows/publish_documentation_website.yml<local_repo_root>/.github/workflows/publish_release_to_pypi.yml
The following files need to be modified according to the specifics of your new Python library:
<local_repo_root>/README.md<local_repo_root>/pyproject.toml<local_repo_root>/.gitignore<local_repo_root>/docs/INSTALL.rst<local_repo_root>/docs/conf.py<local_repo_root>/docs/index.rst<local_repo_root>/docs/literature.rst<local_repo_root>/docs/examples.rst
as well as the files stored in the directories:
<local_repo_root>/<your_lib_name><local_repo_root>/tests<local_repo_root>/examples<local_repo_root>/docs/examples
After making the necessary modifications, you can proceed to test and debug your new Python library.
Metadata
Release files for pylibtemplate 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pylibtemplate-0.0.9.tar.gz | 42.6 kB | With provenance | Details for pylibtemplate-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pylibtemplate-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for pylibtemplate-0.0.9-py3-none-any.whl |
Total release size: 67.7 kB
Release files / pylibtemplate-0.0.9.tar.gz
| Download URL | pylibtemplate-0.0.9.tar.gz |
|---|---|
| Size | 42.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02dceb7c5923af220926bc719923d4642abb68c4ce0ed3b697ae64ec0872027a
|
|
BLAKE2b-256 checksum How to use checksums |
973690582dd1bb80e6268fabf5ede084bf8cb38cf4d9766cd1671aa8db6d8d30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2025.
Transparency logRelease files / pylibtemplate-0.0.9-py3-none-any.whl
| Download URL | pylibtemplate-0.0.9-py3-none-any.whl |
|---|---|
| Size | 25.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52a5eb0a892cfd7ed850108e338f28f202c9dcea018acc821659bbfacd1f2301
|
|
BLAKE2b-256 checksum How to use checksums |
a81ac126a32c79168633960d98f2e8399e3c7b1a0a59e7283da4f696ff144897
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2025.
Transparency logSecurity for pylibtemplate 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pylibtemplate-0.0.9.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.