Skip to content

Commit

Permalink
configured to be partially installed
Browse files Browse the repository at this point in the history
  • Loading branch information
matteocacciola committed Jul 6, 2024
1 parent 6accbd0 commit 28e725e
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 217 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@ that you only import the specific packages you need, thereby preventing any unne

## Install

`pip install fastapi-healthz` or `poetry add fastapi-healthz`
`pip install fastapi-healthz` or `poetry add fastapi-healthz`.

Eventually, you can partially install the package by running

`pip install fastapi-healthz[redis]`

`pip install fastapi-healthz[rabbitmq]`

`pip install fastapi-healthz[database]`

`pip install fastapi-healthz[uri]`

`pip install fastapi-healthz[mongodb]`

to install only the package you really need, with the required dependencies.

## Adding Health Checks

Expand Down
1 change: 1 addition & 0 deletions fastapi_healthz/registry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime, timedelta

from .models import HealthCheckStatusEnum, HealthCheckModel, HealthCheckEntityModel
from .service import HealthCheckAbstract

Expand Down
1 change: 1 addition & 0 deletions fastapi_healthz/route.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Callable, Any
from starlette.responses import JSONResponse
from fastapi.encoders import jsonable_encoder

from .registry import HealthCheckRegistry
from .models import HealthCheckStatusEnum

Expand Down
8 changes: 6 additions & 2 deletions fastapi_healthz/service/database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from sqlalchemy import create_engine, text
from sqlalchemy.orm import sessionmaker
try:
from sqlalchemy import create_engine, text
from sqlalchemy.orm import sessionmaker
except ImportError:
raise ImportError("You must install sqlalchemy to use Database health check")

from .abstract import HealthCheckAbstract
from ..models import HealthCheckStatusEnum

Expand Down
5 changes: 4 additions & 1 deletion fastapi_healthz/service/mongodb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import Any
from pymongo import MongoClient
try:
from pymongo import MongoClient
except ImportError:
raise ImportError("You must install pymongo to use MongoDB health check")

from .abstract import HealthCheckAbstract
from ..models import HealthCheckStatusEnum
Expand Down
6 changes: 5 additions & 1 deletion fastapi_healthz/service/rabbitmq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from ssl import SSLContext, PROTOCOL_TLSv1_2
import pika
try:
import pika
except ImportError:
raise ImportError("You must install pika to use RabbitMQ health check")

from .abstract import HealthCheckAbstract
from ..models import HealthCheckStatusEnum

Expand Down
6 changes: 5 additions & 1 deletion fastapi_healthz/service/redis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import asyncio
import aioredis
import time
import random
try:
import aioredis
except ImportError:
raise ImportError("You must install aioredis to use Redis health check")

from .abstract import HealthCheckAbstract
from ..models import HealthCheckStatusEnum

Expand Down
1 change: 1 addition & 0 deletions fastapi_healthz/service/uri.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from requests import get

from ..models import HealthCheckStatusEnum
from .abstract import HealthCheckAbstract

Expand Down
423 changes: 219 additions & 204 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastapi-healthz"
version = "0.4.1"
version = "0.5.0"
description = "A module to have a FastAPI HealthCheck for database, RabbitMQ server, Redis, MongoDB or external URI to validate their healths."
authors = ["Matteo Cacciola <[email protected]>"]
license = "MIT"
Expand All @@ -13,16 +13,24 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.9"
pika = "^1.3.2"
pika = { version = "^1.3.2", optional = true }
fastapi = "^0.111.0"
pydantic = "^2.7.4"
requests = "^2.31.0"
aioredis = "^2.0.1"
sqlalchemy = "^2.0.22"
pymongo = "^4.7.3"
pydantic = "^2.8.2"
requests = { version = "^2.31.0", optional = true }
aioredis = { version = "^2.0.1", optional = true }
sqlalchemy = { version = "^2.0.22", optional = true }
pymongo = { version = "^4.7.3", optional = true }

[tool.poetry.dev-dependencies]

[tool.poetry.extras]
rabbitmq = ["pika"]
redis = ["aioredis"]
database = ["sqlalchemy", "asyncpg"]
mongodb = ["pymongo"]
uri = ["requests"]
all = ["pika", "aioredis", "sqlalchemy", "asyncpg", "pymongo", "requests"]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 28e725e

Please sign in to comment.