pkgcreator is a Python CLI tool that helps you quickly set up a new Python package with a recommended folder structure, a virtual environment, license file, Git repository, and pre-filled configuration files like pyproject.toml and README.md.
It supports interactive prompts, smart defaults (e.g. from your Git config), and includes additional utilities like a GitHub folder downloader, CLI/formatter helpers, and virtual environment management.
Whether you're preparing a new project or just want a clean setup for your next internal tool — pkgcreator automates the boilerplate and saves you time.
Developed and maintained by Philipp Meder.
- Source code: https://github.com/PhilippMeder/pkgcreator.git
- Report bugs: https://github.com/PhilippMeder/pkgcreator/issues
Quick overview:
- Quick Start
- License
- Features (most interesting part)
- Requirements and Dependencies
Install this package (replace pkgcreator with pkgcreator[full] to install all optional dependencies on Python packages):
pip install pkgcreatorCreate a new package structure, initialise Git, create a virtual environment, and include the MIT license:
pkgcreator create mypackage --git --venv --license MITFor a detailed list of available options, see the section Package Structure Creator.
Distributed under the BSD 3-Clause License.
Following features are covered here, with focus on the main feature Package Structure Creator.
- Package Structure Creator
- Accessing Git with Python
- GitHub Downloader
- Creating and Managing Virtual Environments
- Tools
To use the core features, you may directly call one of the two following lines:
pkgcreator [OPTIONS]
python -m pkgcreator [OPTIONS]For a list of available options, see the next sections or run:
pkgcreator --helpCreate a typical file structure for a python package with the necessary files and their content.
Running pkgcreator create <NAME> will create the following package structure as officially recommended:
NAMEsrc/NAME__init__.py__main__.py(if the--scriptoption is used)
.gitignore(with some presets)LICENSE(with content if the-l, --license>option is used)pyproject.toml(with content according to the options used, see--help)README.md(with content according to the options used, see--help)
For a list of available options, read the next sections or run:
pkgcreator create --helpThere are several important options you may consider when creating the package structure:
-
Adding a license text with
--license <LICENSE>:Using the
-l, --license <LICENSE>option allows you to add the text of<LICENSE>if this is a valid identifier. To list all available identifiers, use--list-licenses. This option requires the python packagerequestsand will fail if it is not installed. -
Initialising a Git repository with
--git:If
Gitis available on your system, using the--gitoption automatically initialises a Git repository and commits all created files. -
Creating a virtual environment with
--venv:Using the
--venvoption automatically creates a virtual environment inNAME/.venv(ignored byGit) and installs the created package in editable mode so you can run it aspython -m <NAME>or import it withimport <NAME>inside the activated environment. -
Providing the package as a script with
--script:Using the
--scriptoption will create a__main__.pywith functionmain()that is called whenever you run the package as a module (python -m <NAME>). In addition, thepyproject.tomlregisters the terminal command<NAME>that will also call this function.
If not explicitly set, some arguments will suggest values based on context:
--github-repositorynamemay suggest using the package name--author-namemay suggest usinguser.namefromgit config, if available--author-mailmay suggest usinguser.emailfromgit config, if available--gitmay ask whether to initialise a Git repository--venvmay ask whether to initialise a virtual environment and install the package in editable mode
Use the -m, --prompt-mode option to control whether these suggestions are shown or automatically handled:
| Option | yes |
auto |
no |
|---|---|---|---|
--github-repositoryname |
✅ | ✅ | ❌ |
--author-name |
✅ | ✅ | ❌ |
--author-mail |
✅ | ✅ | ❌ |
--git |
✅ | ❌ | ❌ |
--venv |
✅ | ❌ | ❌ |
yes: Automatically accept all suggestionsno: Skip all prompts and use defaults or leave unsetauto: Accept safe suggestions only (e.g., use Git info, but skip Git initialisation)ask(default): Prompt interactively for each case, and ask again before creating the project structure
There are a bunch of variables that are used for the creation of the pyproject.toml, README.md, and LICENSE (if -l is used).
These can be changed later in the mentioned files.
Available options are (the names are self-explanatory):
| Option | Notes |
|---|---|
--description |
|
--author-name |
suggests git config user.name if not set |
--author-mail |
suggests git config user.email if not set |
--github-username |
used for various project URLs (if not provided) |
--github-repositoryname |
used for various project URLs (if not provided), suggests the package name if not set |
In addition, a typical package also links to some of its online resources.
If not set, each of them will link to a subpage of the github repository defined by --github-username and --github-repositoryname.
--changelog--documentation--download--funding--homepage--issues--releasenotes--source
If some dependencies, optional dependencies or classifiers (for PyPI) are already known, they can be set with the following commands:
--dependencies package1 package2 ...--optional-dependencies package1 package2 ...(available as a[full]option during package installation)--classifiers classifier1 classifier2 ...(for a full list see PyPI classifier)
This feature is provided for completeness since it is used as a handy tool during the package structure creation process. You may run
pkgcreator git --helpto list the available options. However, running Git directly is usually more flexible and preferred.
Download a specific folder (or the entire contents) from a public GitHub repository using the GitHub API.
Features:
- Downloads a subfolder or the full repository
- Supports branch selection
- Recursive or non-recursive download
Usage:
To download the repository contents (default branch main), run:
pkgcreator github-download <OWNER> <REPOSITORY> [OPTIONS]Available options are (run pkgcreator github-download --help for a full list):
-b, --branchSelects the branch name (default: main).-s, --subfolderIf not provided, download the full repository. If set to a subdirectory of the repository, download this subdirectory. If set to a single file, only download this file.-d, --destinationLocal directory where the files should be downloaded to (default: ./downloaded_).-n, --no-recursiveDo not download folders recursively.--listList the content of the repository (or the given subfolder) and exit.
Note: The GitHub API limits the number of requests per time period. For more information see the Rate limits for the REST API.
For completeness, a bash version is provided.
Located in: github_download.sh
Features:
- Uses
git sparse-checkoutto efficiently fetch only a folder - Minimal download size, ideal for large repositories
Usage:
./github_download.sh ExampleOwner example_repo main ./target_folder subdir/in/repoArguments:
<owner> <repo> [branch=main] [target_dir=<repo>_sparse] [folder=None]
If no folder is specified, the full repository is checked out.
The command
pkgcreator venv [OPTIONS]can create a virtual environment and install packages in this environment.
Available options are (run pkgcreator github-download --help for a full list):
-d, --destinationDirectory where the venv folder will be created (default: current working directory).-c, --createCreate the virtual environment.-i, --installList of packages to install (via pip).-e, --editableList of packages/local package paths to install in editable mode (-e).--nameName of the virtual environment folder (default: .venv).--version-suffixAppend Python major/minor version to the venv folder name.
In addition to the main features, also some useful tools that were written for the functionality of this package are available.
LoggerFormatterprovides a formatter that is a subclass of the standard library'slogging.Formatter. The logger messages will be color coded and start with[Error], [Warning], [Info]depending on the message type.logged_subprocess_runprovides a wrapper aroundsubprocess.runwhere the output feed of the process is streamed live to the given logger.
To use these features and understand their parameters, run:
from pkgcreator.logging_tools import LoggerFormatter, logged_subprocess_run
help(LoggerFormatter)
help(logged_subprocess_run)ConsistentFormatterprovides anargparse.HelpFormatterthat aims at a consistent appearance. It enforces capitalization and periods where needed.generate_parser_templategenerates a template Python function that consistently creates anargparse.Argparserthat is either a standalone or a subparser.
To use these features and understand their parameters, run:
from pkgcreator.cli_tools import ConsistentFormatter, generate_parser_template
help(ConsistentFormatter)
help(generate_parser_template)Following requirements must be satisfied:
Python 3.10+(developed withPython 3.13, tested withPython 3.10+, lower version are not working due to the use ofmatch ... caseandUnion)
Following optional dependencies are recommended, but not required:
requestslibrary (for Python GitHub downloader and license selection/download)Git(for sparse-checkout Bash script or if you want to initialise a Git repository when creating a Python package)
To install Python dependencies you may either use
pip install DEPENDENCYor directly specify that you want to install all optional dependencies when installing this package with:
pip install pkgcreator[full]