PyPI Setup Guide for django-rls
Option 1: Trusted Publishing (Recommended)
This is the most secure method as it doesn't require storing API tokens.
1. Create PyPI Account
- Go to pypi.org and create an account
- Verify your email address
2. Create the Project on PyPI
- Go to pypi.org/manage/projects/
- Click "Add a project"
- Project name:
django-rls
3. Configure Trusted Publishing
- In your PyPI project, go to "Publishing" settings
- Add a new trusted publisher:
- Publisher: GitHub
- Owner:
kdpisda - Repository:
django-rls - Workflow name:
.github/workflows/release.yml - Environment name:
release(important!)
4. Configure GitHub Environments
- Go to your GitHub repo → Settings → Environments
- Create environment:
release - Add protection rules (optional):
- Required reviewers: 1
- Restrict to protected branches
5. For TestPyPI (Optional)
- Create account on test.pypi.org
- Same process as above but with environment name:
test-release
Option 2: API Token Method
If you prefer using API tokens:
1. Get PyPI API Token
- Log in to pypi.org
- Go to Account settings → API tokens
- Add API token:
- Token name:
django-rls-github-actions - Scope: Select "Project: django-rls" (after first manual upload) or "Entire account"
- Token name:
- Copy the token (starts with
pypi-)
2. Add to GitHub Secrets
- Go to GitHub repo → Settings → Secrets and variables → Actions
- New repository secret:
- Name:
PYPI_API_TOKEN - Value: (paste the token)
- Name:
3. Update Workflow
Uncomment the API token lines in .github/workflows/release.yml:
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
First Release Steps
1. Ensure Tests Pass
poetry run pytest
2. Trigger Release
Go to Actions → Release to PyPI → Run workflow:
- Version bump:
patch - This will release v0.1.0
3. Verify
- Check pypi.org/project/django-rls/
- Test installation:
pip install django-rls==0.1.0
Troubleshooting
"Not authorized" Error
- Ensure environment name matches exactly (
release) - Check workflow file path is correct
- Wait a few minutes after configuring (PyPI caches)
"Project not found" Error
- You may need to do first upload manually:
poetry build
poetry publish
Trusted Publishing Not Working
- Ensure
permissions: id-token: writeis in workflow - Check GitHub repo and owner names match exactly
- Environment protection rules might be blocking
Questions for PyPI Form
When PyPI asks for GitHub Actions details:
- Workflow file:
.github/workflows/release.yml - Environment:
release - Owner:
kdpisda - Repository:
django-rls