|
| 1 | +# Publishing to PyPI |
| 2 | + |
| 3 | +## 📦 How to Publish fastapi-create-project to PyPI |
| 4 | + |
| 5 | +### **Prerequisites** |
| 6 | + |
| 7 | +1. **Create PyPI Account**: https://pypi.org/account/register/ |
| 8 | +2. **Create TestPyPI Account** (for testing): https://test.pypi.org/account/register/ |
| 9 | +3. **Install build tools**: |
| 10 | + ```bash |
| 11 | + pip install --upgrade build twine |
| 12 | + ``` |
| 13 | + |
| 14 | +### **Step 1: Clean Previous Builds** |
| 15 | + |
| 16 | +```bash |
| 17 | +cd /Users/pinkleshparjapati/Desktop/fastapi-create-project |
| 18 | +rm -rf dist/ build/ *.egg-info |
| 19 | +``` |
| 20 | + |
| 21 | +### **Step 2: Build the Package** |
| 22 | + |
| 23 | +```bash |
| 24 | +python -m build |
| 25 | +``` |
| 26 | + |
| 27 | +This creates: |
| 28 | +- `dist/fastapi-create-project-0.1.0.tar.gz` (source distribution) |
| 29 | +- `dist/fastapi_create_project-0.1.0-py3-none-any.whl` (wheel) |
| 30 | + |
| 31 | +### **Step 3: Test on TestPyPI (Recommended)** |
| 32 | + |
| 33 | +```bash |
| 34 | +# Upload to TestPyPI |
| 35 | +python -m twine upload --repository testpypi dist/* |
| 36 | + |
| 37 | +# Test installation from TestPyPI |
| 38 | +pip install --index-url https://test.pypi.org/simple/ fastapi-create-project |
| 39 | +``` |
| 40 | + |
| 41 | +### **Step 4: Publish to PyPI** |
| 42 | + |
| 43 | +```bash |
| 44 | +# Upload to PyPI (PRODUCTION) |
| 45 | +python -m twine upload dist/* |
| 46 | +``` |
| 47 | + |
| 48 | +You'll be prompted for your PyPI username and password. |
| 49 | + |
| 50 | +### **Step 5: Verify Installation** |
| 51 | + |
| 52 | +```bash |
| 53 | +# Install from PyPI |
| 54 | +pip install fastapi-create-project |
| 55 | + |
| 56 | +# Test it |
| 57 | +fastapi-create-project --version |
| 58 | +``` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## 🔑 Using API Tokens (Recommended) |
| 63 | + |
| 64 | +Instead of username/password, use API tokens: |
| 65 | + |
| 66 | +1. Go to https://pypi.org/manage/account/token/ |
| 67 | +2. Create a new API token |
| 68 | +3. Create `~/.pypirc`: |
| 69 | + |
| 70 | +```ini |
| 71 | +[pypi] |
| 72 | +username = __token__ |
| 73 | +password = pypi-YOUR-TOKEN-HERE |
| 74 | + |
| 75 | +[testpypi] |
| 76 | +username = __token__ |
| 77 | +password = pypi-YOUR-TESTPYPI-TOKEN-HERE |
| 78 | +``` |
| 79 | + |
| 80 | +Then upload: |
| 81 | +```bash |
| 82 | +python -m twine upload dist/* |
| 83 | +``` |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## 📝 Before Publishing Checklist |
| 88 | + |
| 89 | +- [ ] Update version in `fastapi_scaffold/__init__.py` |
| 90 | +- [ ] Update version in `setup.py` |
| 91 | +- [ ] Update `README.md` with latest features |
| 92 | +- [ ] Test locally: `pip install -e .` |
| 93 | +- [ ] Create a test project and verify it works |
| 94 | +- [ ] Clean build artifacts: `rm -rf dist/ build/ *.egg-info` |
| 95 | +- [ ] Build: `python -m build` |
| 96 | +- [ ] Upload to TestPyPI first |
| 97 | +- [ ] Test installation from TestPyPI |
| 98 | +- [ ] Upload to PyPI |
| 99 | +- [ ] Create Git tag: `git tag v0.1.0 && git push origin v0.1.0` |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## 🔄 Publishing Updates |
| 104 | + |
| 105 | +When releasing a new version: |
| 106 | + |
| 107 | +1. **Update version number** in both files: |
| 108 | + - `fastapi_scaffold/__init__.py` → `__version__ = "0.2.0"` |
| 109 | + - `setup.py` → `version="0.2.0"` |
| 110 | + |
| 111 | +2. **Clean and rebuild**: |
| 112 | + ```bash |
| 113 | + rm -rf dist/ build/ *.egg-info |
| 114 | + python -m build |
| 115 | + ``` |
| 116 | + |
| 117 | +3. **Upload**: |
| 118 | + ```bash |
| 119 | + python -m twine upload dist/* |
| 120 | + ``` |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## 🌐 After Publishing |
| 125 | + |
| 126 | +Your package will be available at: |
| 127 | +- **PyPI**: https://pypi.org/project/fastapi-create-project/ |
| 128 | +- **Installation**: `pip install fastapi-create-project` |
| 129 | + |
| 130 | +Users can install it globally: |
| 131 | +```bash |
| 132 | +pip install fastapi-create-project |
| 133 | +# or |
| 134 | +pipx install fastapi-create-project |
| 135 | +``` |
| 136 | + |
| 137 | +Then use from anywhere: |
| 138 | +```bash |
| 139 | +fastapi-create-project --version |
| 140 | +fastapi-create-project |
| 141 | +``` |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## 🚀 Quick Publish Commands |
| 146 | + |
| 147 | +```bash |
| 148 | +# One-liner for publishing |
| 149 | +cd /Users/pinkleshparjapati/Desktop/fastapi-create-project && \ |
| 150 | +rm -rf dist/ build/ *.egg-info && \ |
| 151 | +python -m build && \ |
| 152 | +python -m twine upload dist/* |
| 153 | +``` |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +## ⚠️ Important Notes |
| 158 | + |
| 159 | +1. **Package name must be unique** on PyPI |
| 160 | +2. **Can't delete or re-upload** same version number |
| 161 | +3. **Test on TestPyPI first** before production |
| 162 | +4. **Use semantic versioning**: MAJOR.MINOR.PATCH (e.g., 0.1.0, 0.2.0, 1.0.0) |
| 163 | +5. **Create GitHub releases** matching your PyPI versions |
| 164 | + |
| 165 | +--- |
| 166 | + |
| 167 | +## 📊 Package Statistics |
| 168 | + |
| 169 | +After publishing, view stats at: |
| 170 | +- https://pypi.org/project/fastapi-create-project/ |
| 171 | +- https://pypistats.org/packages/fastapi-create-project |
| 172 | + |
| 173 | +Track downloads: |
| 174 | +```bash |
| 175 | +pip install pypistats |
| 176 | +pypistats overall fastapi-create-project |
| 177 | +``` |
| 178 | + |
0 commit comments