The goal of this project is to provide a Python-based starter API, which comes pre-configured with tools supporting the accelerated development of both Comet as well as general python APIs. Some of these tools are as follows:
- Platform: Python
- Web Framework: Fast API
- Database: SQLite, Alembic
- ORM: SQLAlchemy
- Data Validation: Pydantic
- Unit Testing: PyTest
- Code Quality: Ruff, PyLint, Black, isort
- Authentication support: JWT
- Documentation: Swagger and ReDoc
- Running the Project Locally
- Running Unit Tests
- Running Code Quality Checks
- Running Code Formatting
- Publishing Updated Docs
- Contributing
- Next Steps
- To create an environment, run the following:
virtualenv -p python3 venv
source venv/bin/activate
- To install project dependencies, run the following:
pip install .
- To install dev dependencies, run the following (optional):
pip install -e ".[dev]"
- To prepare your environment, add a file called
.env
to thecomet-api
directory. Copy and paste the template below and replace the placeholder values with your own:
DATABASE_URL=[SOME_URL] # Ex: 'sqlite:///./db.sqlite3'
OIDC_CONFIG_URL=[SOME_URL] # Ex: 'https://token.actions.githubusercontent.com/.well-known/openid-configuration'
- To start the app, run the following:
uvicorn app.main:app --reload --host=0.0.0.0 --port=5000
- Access the swagger docs by navigating to:
http://0.0.0.0:5000/docs
- To run unit tests, run the following:
pytest
- To run unit tests with code coverage, run the following:
coverage run -m pytest && coverage html
- To run code quality checks, run the following:
ruff check .
- To run code formatting, run the following:
ruff format .
-
Access the swagger ReDocs by navigating to:
http://0.0.0.0:5000/redoc
-
Download the OpenAPI spec, click the Download button
-
Navigate to
https://editor.swagger.io/#/
-
Upload the spec, click File >> Import File and select the spec file previously downloaded
-
Download the converted spec, click Generate Client >> openapi-yaml
-
Copy the downloaded file into the
comet-api/docs
directory -
Convert the yaml into html run the following:
npx redoc-cli bundle docs/openapi.yaml
- Copy the generated html to the docs directory, run the following:
mv redoc-static.html docs/index.html
- Commit the spec and html files and merge into
main
to publish docs
- Fork the Project
- Create your Feature Branch (
git checkout -b feature_a
) - Commit your Changes (
git commit -m 'Added new feature_a'
) - Push to the Branch (
git push origin feature_a
) - Open a Pull Request
The following provides a short list of tasks which are potential next steps for this project. These could be steps in making use of this baseline or they could be for learning purposes.
- Add/Update existing endpoints with more applicable entities and/or columns
- Update applicable endpoints to require JWT
- Add Admin endpoints to support password reset
- Replace default database with external database (Ex. Postgres)
- Deploy to cloud infrastructure
- Automate doc publishing process