A unified, provider-agnostic chat completions API server supporting OpenAI and AWS Bedrock
This guide outlines the steps to package the open-bedrock-server
project and publish it to the Python Package Index (PyPI).
Publishing to PyPI makes your package easily installable for other Python users via pip
(or uv pip
). It also provides a central place for users to find your package and its documentation.
Before you begin, ensure you have:
pyproject.toml
).uv
installed: A fast Python package installer. If not installed, see uv installation guide.build
and twine
. These will be installed in a later step.pyproject.toml
Your pyproject.toml
file is the heart of your package’s configuration. Ensure it’s complete and accurate.
Key sections to review and update:
name
: Should be unique on PyPI. open_bedrock_server
is likely fine.version
: Update this for each new release (e.g., 0.1.0
, 0.1.1
, 0.2.0
).authors
: Provide your name and email.description
: A short, one-sentence summary of the package.readme
: Points to your README.md
file, which will be used as the long description on PyPI.requires-python
: Ensure this reflects the Python versions your package supports (e.g., >=3.8
).license
: Specify the license (e.g., {text = "MIT"}
).[project.dependencies]
):
fastapi>=0.115.0
, click>=8.1.0
.[project.keywords]
):
keywords = ["llm", "chatbot", "openai", "aws", "bedrock", "chat", "api", "cli"]
[project.classifiers]
):
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Communications :: Chat",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities"
]
[project.urls]
):
[project.urls]
"Homepage" = "https://github.com/yourusername/open-bedrock-server"
"Bug Tracker" = "https://github.com/yourusername/open-bedrock-server/issues"
"Documentation" = "https://github.com/yourusername/open-bedrock-server/blob/main/README.md"
[project.scripts]
):
bedrock-chat = "src.open_bedrock_server.cli.main:cli"
(This seems correct based on your current structure).[build-system]
):
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[project.optional-dependencies]
):
pytest
, pytest-asyncio
, httpx
for testing) here.[project.optional-dependencies]
dev = [
"pytest>=7.0",
"pytest-asyncio>=0.20",
"httpx>=0.23", # For TestClient
# Add other dev tools like linters, formatters if desired
]
uv pip install .[dev]
.[tool.setuptools.packages.find]
):
src/
.where = ["src"]
(This seems correct).README.md
Your README.md
file will be displayed on your PyPI project page.
.gitignore
file to ensure that build artifacts (like dist/
, build/
, *.egg-info/
), virtual environments (.venv/
), and other non-source files are excluded from Git.dist/
, build/
, or *.egg-info/
directories before building to ensure a clean build.Install the necessary tools for building and uploading your package:
uv pip install build twine
Install these in your global Python environment or a dedicated packaging virtual environment, not necessarily your project’s virtual environment unless you add them to dev dependencies.
Navigate to your project’s root directory (where pyproject.toml
is located) and run:
python -m build
This command will create a dist/
directory containing two files:
open_bedrock_server-0.1.0.tar.gz
)open_bedrock_server-0.1.0-py3-none-any.whl
)The wheel is a pre-compiled package format that’s faster to install.
Before uploading, it’s crucial to test if your package installs and works correctly from the built files.
uv venv ../test_packaging_env # Create it outside your project directory
source ../test_packaging_env/bin/activate
dist/
directory (replace with your actual filename):
uv pip install /path/to/your/project/dist/open_bedrock_server-0.1.0-py3-none-any.whl
bedrock-chat --help
bedrock-chat serve --help
# Try running the server and chat client if possible, or at least check if commands are recognized.
deactivate
# rm -rf ../test_packaging_env
TestPyPI is a separate instance of PyPI for testing the distribution process without affecting the real index.
~/.pypirc
to make uploading easier:
[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = your_testpypi_api_token
Generate an API token from your TestPyPI account settings. Using __token__
as the username is required for API tokens.
~/.pypirc
configured:
twine upload --repository testpypi dist/*
If not, you’ll be prompted for your TestPyPI username and password (use __token__
for username and the token value for password):
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Verify on TestPyPI:
Go to https://test.pypi.org/project/open-bedrock-server/
to see your uploaded package.
uv pip install --index-url https://test.pypi.org/simple/ open-bedrock-server
# Or, to include pre-releases if your version is like 0.1.0a1:
# uv pip install --index-url https://test.pypi.org/simple/ --pre open-bedrock-server
Test the installed package as in Step 6.
Once you’re confident that your package works correctly and you’ve tested it on TestPyPI, you can upload it to the official PyPI.
~/.pypirc
:
[pypi]
username = __token__
password = your_pypi_api_token
Generate an API token from your PyPI account settings.
dist/*
files.
If you have ~/.pypirc
configured:
twine upload dist/*
If not, you’ll be prompted (use __token__
for username and the token value for password):
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
Caution: Once a version is uploaded to PyPI, it cannot be overwritten. You’ll need to upload a new version if you find issues.
After a successful PyPI release, create a Git tag for this version:
git tag v0.1.0 # Or your current version
git push origin v0.1.0
This helps track which commit corresponds to which release.
https://pypi.org/project/open-bedrock-server/
).pyproject.toml
and repeat the build and upload process.This guide provides a comprehensive overview. Remember to replace placeholders like your-package-name
, yourusername
, and version numbers with your actual project details.