📟 FastAPI Calculator + Calculator-Lib
Projeto completo usando Python, FastAPI, Docker, GitHub Packages e GitHub Actions!
📚 O que esse projeto faz?
calculator-lib: biblioteca Python de operações matemáticas básicas.fastapi-calculator: serviço FastAPI que usa a calculator-lib para cálculos.- CI/CD Automático: testes → build → publicação no GitHub Packages → build da API → publicação da imagem Docker.
⚙️ Fluxo de CI/CD (GitHub Actions)
- Testa a biblioteca
calculator-lib - Publica a biblioteca no GitHub Packages
- Testa o serviço
fastapi-calculator - Builda e publica o container Docker no GitHub Container Registry (
ghcr.io)
✅ Cada etapa depende da anterior para garantir a qualidade!
📦 Instalação local
📚 1. Instalar a biblioteca calculator-lib
Se publicada no PyPI ou GitHub Packages:
pip install calculator-lib
Se localmente:
python -m pip install .
🚀 2. Rodar o serviço FastAPI
Instale as dependências:
python -m pip install -r requirements.txt
Suba a API:
uvicorn app.main:app --reload
Acesse: 👉 http://localhost:8000/docs
🐳 Rodar usando Docker e Docker Compose
📋 Buildar e rodar
make docker-build # Builda a imagem usando docker compose
make docker-up # Sobe o serviço
ou em modo detached:
make docker-up-detached
Para derrubar:
make docker-down
Para limpar tudo (imagens, volumes):
make docker-clean
🛠️ Makefile: Comandos úteis
| Comando | Ação |
|---|---|
make install |
Instalar dependências da API |
make install-lib |
Instalar calculator-lib |
make install-dev |
Instalar ferramentas de desenvolvimento |
make test-lib |
Testar a biblioteca |
make test-app |
Testar a API |
make build-lib |
Buildar lib tradicional (setup.py) |
make build-modern |
Buildar lib moderno (python -m build) |
make publish-lib |
Publicar lib (quando configurado) |
make docker-build |
Buildar imagem Docker via Compose |
make docker-up |
Subir serviço Docker |
make docker-up-detached |
Subir serviço em background |
make docker-down |
Derrubar containers |
make docker-clean |
Limpar containers, imagens, volumes |
📚 Publicação manual da calculator-lib
🛠️ Passo a passo
- Instalar ferramentas de build:
make install-dev
Ou diretamente:
python -m pip install build twine wheel
- Buildar a lib:
make build-modern
ou
python -m build
Isso vai gerar a pasta dist/ contendo .tar.gz e .whl.
- Publicar no GitHub Packages (ou PyPI)
Se configurado para GitHub Packages:
python -m twine upload dist/*
Lembre-se de configurar seu
.pypirce usar oGITHUB_TOKENouTWINE_USERNAME/TWINE_PASSWORD.
📂 Estrutura do Projeto
fastapi-calculator/
├── app/
│ ├── main.py
│ ├── models.py
├── calculator_lib/
│ ├── __init__.py
│ └── operations.py
├── tests/
│ └── test_main.py
├── tests_lib/
│ └── test_operations.py
├── docker-compose.yml
├── Dockerfile
├── Makefile
├── README.md
├── setup.py
├── pyproject.toml
└── .github/
└── workflows/
└── test-and-deploy.yml
testando a lib de novo!!!!!!!
Metadata
Release files for calculadora-saraiva-lib 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| calculadora_saraiva_lib-0.1.5.tar.gz | 3.8 kB | Without provenance | Details for calculadora_saraiva_lib-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| calculadora_saraiva_lib-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for calculadora_saraiva_lib-0.1.5-py3-none-any.whl |
Total release size: 7.9 kB
Release files / calculadora_saraiva_lib-0.1.5.tar.gz
| Download URL | calculadora_saraiva_lib-0.1.5.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a3f05f2fb58eec00db02d5c2f1f04ae5fd09978c4ce9e3192557666a74f68d65
|
|
BLAKE2b-256 checksum How to use checksums |
56d3824b33a4c0e15b2f334c4ba20c39299d763931641a34e163c7772947a4aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / calculadora_saraiva_lib-0.1.5-py3-none-any.whl
| Download URL | calculadora_saraiva_lib-0.1.5-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ff547e061a61d5c581b4ec3dc7aa02c8e82343951bb3bdc53db3ae64cd60ed1
|
|
BLAKE2b-256 checksum How to use checksums |
5bbd85b01a9252cf61176934b6dc8fb9992716b7375dd15c4d27715bd8af060a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Security for calculadora-saraiva-lib 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.