Plugins for FastAPI framework
Project description
Plugins for FastAPI framework, high performance, easy to learn, fast to code, ready for production
fastapi-plugins
FastAPI framework plugins
- Redis
- Celery
- MQ
- Logging
- Health
- Common
Changes
See release notes
Installation
pip install fastapi-plugins
Plugins
Redis
Supports
- single instance
- cluster NOT SUPPORTED NOW
- fake redis NOT SUPPORTED NOW
Valid variable are
REDIS_TYPE
redis
- single Redis isntancesentinel
- Redis clusterfake
- by using fake Redis
REDIS_URL
- URL to connect to Redis server. Exampleredis://user:password@localhost:6379/2
. Supports protocolsredis://
,rediss://
(redis over TLS) andunix://
.REDIS_HOST
- Redis server host.REDIS_PORT
- Redis server port. Default is6379
.REDIS_PASSWORD
- Redis password for server.REDIS_DB
- Redis db (zero-based number index). Default is0
.REDIS_CONNECTION_TIMEOUT
- Redis connection timeout. Default is2
.REDIS_SENTINELS
- List or a tuple of Redis sentinel addresses.REDIS_SENTINEL_MASTER
- The name of the master server in a sentinel configuration.
Example
# run with `uvicorn demo_app:app`
import typing
import aioredis
import fastapi
import pydantic
import fastapi_plugins
class AppSettings(OtherSettings, fastapi_plugins.RedisSettings):
api_name: str = str(__name__)
app = fastapi.FastAPI()
config = AppSettings()
@app.get("/")
async def root_get(
cache: aioredis.Redis=fastapi.Depends(fastapi_plugins.depends_redis),
) -> typing.Dict:
return dict(ping=await cache.ping())
@app.on_event('startup')
async def on_startup() -> None:
await fastapi_plugins.redis_plugin.init_app(app, config=config)
await fastapi_plugins.redis_plugin.init()
@app.on_event('shutdown')
async def on_shutdown() -> None:
await fastapi_plugins.redis_plugin.terminate()
Example with Docker Compose
version: '3.7'
services:
redis:
image: redis
ports:
- "6379:6379"
demo_fastapi_plugin:
image: demo_fastapi_plugin
environment:
- REDIS_TYPE=redis
- REDIS_HOST=redis
- REDIS_PORT=6379
ports:
- "8000:8000"
... more already in progress ...
Development
Issues and suggestions are welcome through issues
License
This project is licensed under the terms of the MIT license.
Changes
0.1.0 (2019-11-20)
- Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi-plugins-0.1.0.tar.gz
(5.9 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_plugins-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f30f4245493a292b23e640c971fd992899f8a3c829abbdd913dcc5b7efa1b54 |
|
MD5 | b90f3fa566e163f945fb955ea73c0ee7 |
|
BLAKE2b-256 | 9775555c93b235a01d7ee883549b79f318e50456797587118ea1fec154864f4b |