Skip to main content

fast-resource is a data transformation layer that sits between the database and the application's users, enabling quick data retrieval. It further enhances performance by caching data using Redis and Memcached.

Project description

fast-resource

fast-resource is a data transformation layer that sits between the database and the application's users, enabling quick data retrieval. It further enhances performance by caching data using Redis and Memcached.

Why Use fast-resource?

fast-resource is useful in situations where there are numerous data retrieval queries, multiple data sources requiring data aggregation, and shared data between entities that need to be cached. Additionally, the type of database used is not important.

Requirements

  • redis
  • pymemcache

Install

> pip install fast-resource

Usage

Quick Start

from fast_resource import Resource


class UserResource(Resource):
    class Meta:
        fields = (
            'id',
            'name',
        )

    def name(self, input_data) -> str:
        return f'{input_data["name"]} {input_data["family"]}'


UserResource({'id': 1, 'name': 'bagher', 'family': 'rokni'}).to_dict()

Custom output

UserResource({'id': 1, 'name': 'bagher', 'family': 'rokni'}).to_dict(('id',))

Use cache decoder

from redis.client import Redis
from fast_resource import Resource, cache
from fast_resource.cache import RedisCache

def my_key_builder(input_data, field):
    return f'user.{input_data["id"]}.{field}'

class UserResource(Resource):
    class Meta:
        fields = (
            'id',
            'name',
        )

    @cache(key=my_key_builder)
    def name(self, input_data) -> str:
        return f'{input_data["name"]} {input_data["family"]}'


Resource.cache_init(driver=RedisCache(Redis()))
UserResource({'id': 1, 'name': 'bagher', 'family': 'rokni'}).to_dict()

Custom cache expire_time

@cache(key=my_key_builder, expire_time=60)
def name(self, input_data) -> str:
    return f'{input_data["name"]} {input_data["family"]}'

Cache delete

UserResource({'id': 1, 'name': 'bagher', 'family': 'rokni'}).cache_delete()

Cache delete & rebuild

UserResource({'id': 1, 'name': 'bagher', 'family': 'rokni'}).cache_delete(rebuild=True)

Cache delete by keys

UserResource.cache_delete_by_keys(['user.1.name'])

Create collection

user_collection = UserResource.collection([
    {'id': 1, 'name': 'bagher', 'family': 'rokni'},
    {'id': 2, 'name': 'sepehr', 'family': 'rokni'},
    {'id': 3, 'name': 'sama', 'family': 'rokni'},
])
user_collection.to_dict()

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

fast-resource-0.1.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

fast_resource-0.1.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file fast-resource-0.1.1.tar.gz.

File metadata

  • Download URL: fast-resource-0.1.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.0

File hashes

Hashes for fast-resource-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bdfd04f35ca8713728306e39d814f3e26ed88be3def98f4b124f670d888533bc
MD5 07874fd87ea57c6aac594e147ad82b59
BLAKE2b-256 917883bacb2bfc3123a2f9015591aa5f0ff14f7a96d737320228bf601552669a

See more details on using hashes here.

File details

Details for the file fast_resource-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fast_resource-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 94bf66ebe2e105020c90e252bfd6e50b844509d89d9b5c95c86af0c596309955
MD5 9605bcae8176d083aa23ed03695fcca0
BLAKE2b-256 65a13404d58bca32d0131f60ffb22394ca11c1f6449d096ee25c5b2c42fd16ed

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