Skip to main content

Cache Implementation Extension for FastAPI Asynchronous Web Framework

Project description

FastAPI Cachette

Build Status Package Vesion Format Python Version License

Features

Cache Extension for FastAPI Asynchronous Web Framework Most of the Backend implementation is directly lifted from fastapi-cache by @long2ice excluding the MongoDB backend option.

Upcoming Features (To-Do List)

  1. Implement flush and flush_expired methods on individual backends (Not needed for Redis & Memcached backends)

  2. Implement options for encoding/decoding cache data using built-in protocols such as pickle, json or third-party protocol such as msgpack, parquet, feather, hdf5

  3. Write more examples

Installation

The easiest way to start working with this extension with pip

pip install fastapi-cachette
# or
poetry add fastapi-cachette

Getting Started

This FastAPI extension utilizes "Dependency Injection" (To be continued)

Configuration of this FastAPI extension must be done at startup using "@Cachette.load_config" decorator (To be continued)

These are all available options with explanations and validation requirements (To be continued)

Examples

The following examples show you how to integrate this extension to a FastAPI App (To be continued)

See "examples/" folders

To run examples, first you must install extra dependencies

Do all in one go with this command...

pip install aiobotocore aiomcache motor uvicorn redis
# or
poetry install --extras examples

Do individual example with this command...

pip install redis
# or
poetry install --extras redis
# or
poetry install --extras `<example-name>`

Contributions

See features and write tests I guess.

Test Environment Setup

This project utilizes multiple external backend services namely AWS DynamoDB, Memcached, MongoDB and Redis as backend service options as well as a possible internal option called InMemoryBackend. In order to test viability, we must have specific instances of these set up in the background of our testing environment

With Docker-Compose

Utilize orchestration file attached to reposity and docker-compose command to set up testing instances of backend services using the following command...

docker-compose up -d

When you are finished, you can stop and remove background running backend instances with the following command...

docker-compose down

Without Docker-Compose

If you are using arm64 architecture on your local machine like I am with my fancy MacBook Pro, there is a chance that your docker-compose (V1) is not properly configured and have caused you many headaches. The following commands will allow you to replicate docker-compose orchestration command given above.

  1. AWS DynamoDB Local

    docker run --detach --rm -ti -p 8000:8000 --name cachette-dynamodb amazon/dynamodb-local:latest
    
  2. Memcached

    docker run --detach --rm -ti -p 11211:11211 --name cachette-memcached memcached:bullseye
    
  3. MongoDB

    docker run --detach --rm -ti -p 27017:27017 --name cachette-mongodb mongo:latest
    
  4. Redis

    docker run --detach --rm -ti -p 6379:6379 --name cachette-redis redis:bullseye
    

And finally, to stop and remove running instances, run the following command

[ -n $(docker ps -f name="cachette-*" -q) ] && docker kill $(docker ps -f name="cachette-*" -q)

Tests

Now that you have background running backend instances, you can proceed with the tests by using pytest command as such...

pytest

Or you can configure the command to run specific tests as such...

pytest -k test_load_invalid_configs
# or
pytest -k test_set_then_clear

All test suites must be placed under tests/ folder or its subfolders.

License

This project is licensed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi-cachette-0.1.3.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

fastapi_cachette-0.1.3-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-cachette-0.1.3.tar.gz.

File metadata

  • Download URL: fastapi-cachette-0.1.3.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.13 Darwin/21.0.1

File hashes

Hashes for fastapi-cachette-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fd25c4992a780285403c1c944f47bbfd8fb8d263ceec34325628b0ee286140cd
MD5 1001eee2a481e93c58c199b05b8c59a6
BLAKE2b-256 1f88659f0836e27072fd4369c129215e53b1e51bfb7648dc9085c6f99533bf93

See more details on using hashes here.

File details

Details for the file fastapi_cachette-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_cachette-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 77ce8c72acde7ead4b5d55d035c1a189527459a7c6f7c4a6030802736a731f8f
MD5 0bb491a0dbbc7f7c5b4c1054db6f3712
BLAKE2b-256 c877fcebe997888398a587b82ade454ffac4c28b4fdbc397f57df83f6d6a9337

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page