Giter VIP home page Giter VIP logo

strawberry-ratelimit's Introduction

Strawberry GraphQL Ratelimit Extension

Installation

pip3 install strawberry-ratelimit

Usage

from strawberry_ratelimit.ratelimit import ExtensionRatelimit

...


DEPTH_MAX = 50
CALL_MAX = 500

my_schema = strawberry.Schema(
    query=Query,
    mutation=Mutation,
    extensions=[
        # 60req/min
        ExtensionRatelimit(
            type_name=['getUser', 'updateUser', 'user_friends'], # queries, mutations, internal funcs.
            rate_max=60,
            rate_seconds=60,
            depth_max=DEPTH_MAX, # Maximum depth of the query
            call_max=CALL_MAX # Maximum call count
        ),
        # 1000req/hr
        ExtensionRatelimit(
            type_name=['getFriend', 'updateFriend', 'user_profile'], # queries, mutations, internal funcs.
            rate_max=1000,
            rate_seconds=3600,
            depth_max=DEPTH_MAX, # Maximum depth of the query
            call_max=CALL_MAX # Maximum call count
        ),        
    ]
)

Limitations

  • Consider this project as a reference code. Do not use it for production.

    • Currently, the code uses a single global dict variable to store users' query/mutation accesses.
    • Although there is a code to flush the list of user's IP after a certain amount of logs, the code itself does not collect garbage and it may consume a lot of memory depending on the number of users.
    • It is recommended to re-write this code with DB support for optimization.

strawberry-ratelimit's People

Contributors

stypr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.