Project: pygitweb
# PyGitWeb: Project hosting with FastAPI and pygit2
PyGitWeb is a self-hosted project hosting server. With PyGitWeb you can:
- Self-host git repositories, along with their settings, permissions, and metadata
- Manage projects and teams, with built-in issues and kanban boards
- Protect your code with per-ref push permissions, protected branch patterns, and custom hooks
- Authenticate users through OAuth2 flows, with Google or GitHub, so they don't need to create a separate account
**PyGitTools** is the core package underlying PyGitWeb. It works on its own, without the web server, and lets you:
- Script Python workflows with Tasks, Merge Requests, and Hooks within a repository
- Set up hooks and actions. Actions are defined in configuration and can be used to run checks such as linting and tests before you commit
- Use the bundled git terminal app, `pgt`, to quickly perform git actions and manage tasks from the CLI
The `pygitweb` package depends on `pygittools`, so installing PyGitWeb gives you `pgt` as well.
## Requirements
- Python 3.12 or newer
- [uv](https://docs.astral.sh/uv/) <!-- TODO: minimum version, if any -->
<!-- TODO: note whether a system libgit2 is needed or the pygit2 wheels are sufficient -->
## Quick start
Run PyGitWeb with uv (works in bash or PowerShell):
```bash
uv run --with pygitweb uvicorn pygitweb.main:app
```
By default, this sets up local authentication and creates an `admin` account with a randomly generated password. On first run, the password is printed to the terminal (stderr) and a hashed copy is saved in `~/.pygitweb/auth.json`. To set your own credentials, edit that file.
The server listens on `http://127.0.0.1:8000`, which is reachable only from your own machine.
### Running without authentication
For purely local use, you can disable authentication by setting `PYGITWEB_AUTH` to `0`, `false`, `no`, `off`, or `none` (case-insensitive). An empty value counts as unset, which leaves authentication on.
```bash
PYGITWEB_AUTH=0 uv run --with pygitweb uvicorn pygitweb.main:app
```
```powershell
$env:PYGITWEB_AUTH=0; uv run --with pygitweb uvicorn pygitweb.main:app
```
> [!WARNING]
> With authentication disabled, anyone who can reach the server has full access. Keep the default `127.0.0.1` binding: **never** combine `PYGITWEB_AUTH=0` with `--host 0.0.0.0`, a reverse proxy, or anything else that exposes the server to other machines.
>
> **Disabling auth is saved.** PyGitWeb writes its settings, including `AUTH`, to `~/.pygitweb/settings.json` on every start. After one run with `PYGITWEB_AUTH=0`, later runs stay unauthenticated even once the variable is gone. To turn authentication back on, start the server with `PYGITWEB_AUTH=1`, or set `"AUTH": true` in `settings.json`.
### Trying `pgt` on its own
To evaluate `pgt` without the web server, run it from inside any git repository:
```bash
uvx --from pygittools pgt
```
Or install it permanently:
```bash
uv tool install pygittools
pgt
```
## Configuration
PyGitWeb keeps its configuration in `~/.pygitweb/`:
- `settings.json` holds server settings. It is created on first run from your environment.
- `auth.json` holds local users and OAuth settings.
Settings come from `PYGITWEB_*` environment variables or a `.env` file in the working directory. When `settings.json` already exists, environment variables override it, PyGitWeb prints a warning, and the new values are **saved back to the file**.
PyGitWeb serves the git repositories it finds under `PYGITWEB_PROJECTROOT`. That defaults to your home directory, so set it to the folder that holds your repositories.
| Variable | Default | Description |
| --- | --- | --- |
| `PYGITWEB_AUTH` | enabled | Set to `0` to disable authentication (local use only; see above) |
| `PYGITWEB_AUTH_CONFIG` | `~/.pygitweb/auth.json` | Path to the auth config file |
| `PYGITWEB_SETTINGS_CONFIG` | `~/.pygitweb/settings.json` | Path to the settings file |
| `PYGITWEB_CAPACITY_CONFIG` | `~/.pygitweb/capacity.json` | Path to the sprint capacity file (weekly story points per user) |
| `PYGITWEB_PROJECTROOT` | your home directory | Folder that is scanned for repositories |
| `PYGITWEB_PROJECTS_LIST` | `PYGITWEB_PROJECTROOT` | Folder to scan, or a gitweb-style file with one `path owner` per line |
| `PYGITWEB_PROJECT_MAXDEPTH` | `1` | How many folder levels below the root are scanned for repositories |
| `PYGITWEB_SITE_NAME` | `PyGitWeb` | Name shown in the web UI |
| `PYGITWEB_LIST_ALL` | `true` | List every repository found. Set to `false` to require the `EXPORT_OK` marker file. |
| `PYGITWEB_EXPORT_OK` | | Marker file a repository needs before it is listed, as in gitweb's `$export_ok` |
| `PYGITWEB_STRICT_EXPORT` | `false` | Only allow access to repositories that appear in the project list, as in gitweb's `$strict_export` |
| `PYGITWEB_GIT` | `git` | Path to the `git` executable |
| `PYGITWEB_MAXLOAD` | none | Return 503 while the system load average is above this value |
| `PYGITWEB_ENABLED_PLUGINS` | `[]` | Plugins to enable (JSON list) |
| `PYGITWEB_API_KEY_MAX_COUNT` | `2` | Maximum number of API keys per user |
| `PYGITWEB_API_KEY_EXPIRY_DAYS` | `0` | How many days new API keys last (`0` means they never expire) |
## Installation with Docker
Coming soon.
## Planned
These features are not available yet:
- SSH access
- Secret scanning and better repository search
- Commit signing and trust features
- PostgreSQL and SQLite backends
- Git LFS support out of the box
## Development
Clone the repository over smart-HTTP, install all workspace packages, and start the server with auto-reload:
```bash
git clone https://app.pygitweb.com/http/pygitweb
cd pygitweb && uv sync --all-packages --all-groups
uv run uvicorn pygitweb.main:app --reload
```
The repository is a uv workspace with four packages:
| Folder | Package |
| --- | --- |
| `pygitweb/` | The FastAPI web server |
| `pygittools/` | Core git, task, and hook library, plus the `pgt` terminal app |
| `pygittools-mcp/` | MCP server that exposes pygittools task boards to AI clients |
| `postgit/` | Tools for moving data between git and PostgreSQL |
Cloning and pushing currently work over smart-HTTP only. SSH access is planned.
### Pre-commit checks
The pre-commit checks are defined as `pgt` actions under `[tool.pgt]` in `pyproject.toml`, and each one runs a script in `scripts/`. You can run them from `pgt`, or run the same checks by hand:
```bash
uv run ruff check --fix && \
uv run ruff format --preview && \
uv run mypy . && \
uv run pytest .
```
### Browser tests
The optional Playwright tests need browser binaries installed once before the first run:
```bash
uv run playwright install
uv run pytest . --playwright --js-tests
```
### Coverage
```bash
uv run coverage run -m pytest . && uv run coverage html
```
The report is written to `htmlcov/index.html`.
## Contributing
<!-- TODO: how to report issues and submit merge requests -->
## License
PyGitWeb and PyGitTools are released under the MIT License. See `pygitweb/LICENSE` and `pygittools/LICENSE`.