Python Decorators

Open-source Python projects categorized as Decorators Edit details

Top 12 Python Decorator Projects

  • httpretty

    Intercept HTTP requests at the Python socket level. Fakes the whole socket module (by gabrielfalcao)

  • enforce

    Python 3.5+ runtime type checking for integration testing and data validation

    Project mention: Python’s “Type Hints” are a bit of a disappointment to me | | 2022-04-21

    Every point in this blog post strikes me as either (1) unaware of the tooling around python typing other than mypy, or (2) a criticism of static-typing-bolted-on-to-a-dynamically-typed-language, rather than Python's hints. Regarding (1), my advise to OP is to try out Pyright, Pydantic, and Typeguard. Pyright, especailly, is amazing and makes the process of working with type hints 2 or 3 times smoother IMO. And, I don't think points that fall under (2) are fair criticisms of type *hints*. They are called hints for a reason.

    Otherwise, here's a point-by-point response, either recommending OP checks out tooling, or showing that the point being made is not specific to Python.

    > type hints are not binding.

    There are projects [0][1] that allow you to enforce type hints at runtime if you so choose.

    It's worth mentioning that this is very analogous to how Typescript does it, in that type info is erased completely at runtime.

    > Type checking is your job after all, ...[and that] requires maintenance.

    There are LSPs like Pyright[2] (pyright specifically is the absolute best, IMO) that report type errors as you code. Again, this is very very similar to typescript.

    > There is an Any type and it renders everything useless

    I have never seen a static-typing tool that was bolted on to a dynamically typed language, without an `Any` type, including typescript.

    > Duck type compatibility of int and float

    The author admits that they cannot state why this behavior is problematic, except for saying that it's "ambiguous".

    > Most projects need third-party type hints

    Again, this is a criticism of all cases where static types are bolted on dynamically typed languages, not Python's implementation specifically.

    > Sadly, dataclasses ignore type hints as well

    Pydantic[3] is an amazing data parsing library that takes advantage of type hints, and it's interface is a superset of that of dataclasses. What's more, it underpins FastAPI[4], an amazing API-backend framework (with 44K Github stars).

    > Type inference and lazy programmers

    The argument of this section boils down to using `Any` as a generic argument not being an error by default. This is configurable to be an error both in Pyright[5], and mypy[6].

    > Exceptions are not covered [like Java]

    I can't find the interview/presentation, but Guido Van Rossum specifically calls out Java's implementation of "exception annotations" as a demonstration of why that is a bad idea, and that it would never happen in Python. I'm not saying Guido's opinion is the absolute truth, but just letting you know that this is an explicit decision, not an unwanted shortcoming.








  • SonarQube

    Static code analysis for 29 languages.. Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free.

  • Cachier

    Persistent, stale-free, local and cross-machine caching for Python functions.

  • Deal

    Design by contract for Python. Write bug-free code. Add a few decorators, get static analysis and tests for free.

    Project mention: deal: Design by contract for Python. Write bug-free code. Add a few decorators, get static analysis and tests for free. | | 2022-05-26
  • lambda-decorators

    🐍λ✨ - A collection of useful decorators for making AWS Lambda handlers

    Project mention: Your CORS and API Gateway survival guide | | 2022-03-15

    If you’re a Pythonista, Daniel Schep has made a nice lambda-decorators library with the same goals as Middy—replacing Lambda boilerplate.

  • stupid-python-tricks

    Stupid Python tricks.

  • paprika

    Paprika is a python library that reduces boilerplate. Heavily inspired by Project Lombok.

  • Scout APM

    Less time debugging, more time building. Scout APM allows you to find and fix performance issues with no hassle. Now with error monitoring and external services monitoring, Scout is a developer's best friend when it comes to application development.

  • fastapi-class

    Generate Class & Decorators for your FastAPI project ✨🚀

    Project mention: Generate Class & Decorators for your FastAPI project ✨ | | 2021-10-10

    You could now check the package source here:

  • pyeventbus

    Python Eventbus

  • DecoRouter

    FastAPI style routing for starlette

    Project mention: FastAPI style routing for starlette | | 2022-03-04

    DecoRouter brings back the decorator functionality to starlette which was deprecated since 1.13.0. This makes migrating from frameworks like FastAPI and Flask easier and code cleaner.

  • telegrask

    Flask-inspired Telegram bot micro framework for Python.

    Project mention: Micro framework for bots around python-telegram-bot (early development) | | 2021-08-26
  • decfunc

    Creating decorators with arguments made easy.

    Project mention: decfunc - a library to create decorators in a simple way, using classes | | 2022-01-16

    u/Rawing7 Hey, thanks to your comment, I inspected my code and found some other major problems.I was able to fix them by some refactoring. And I also realized & understood your point on writing decorators via functions. Also, If it is OK with you, I could insert your name into the contributors file.

NOTE: The open source projects on this list are ordered by number of github stars. The number of mentions indicates repo mentiontions in the last 12 Months or since we started tracking (Dec 2020). The latest post mention was on 2022-05-26.

Python Decorators related posts


What are some of the best open-source Decorator projects in Python? This list will help you:

Project Stars
1 httpretty 1,956
2 enforce 531
3 Cachier 404
4 Deal 402
5 lambda-decorators 226
6 stupid-python-tricks 112
7 paprika 47
8 fastapi-class 34
9 pyeventbus 16
10 DecoRouter 14
11 telegrask 10
12 decfunc 3
Find remote jobs at our new job board There are 4 new remote jobs listed recently.
Are you hiring? Post a new remote job listing for free.
Developer Ecosystem Survey 2022
Take part in the Developer Ecosystem Survey 2022 by JetBrains and get a chance to win a Macbook, a Nvidia graphics card, or other prizes. We’ll create an infographic full of stats, and you’ll get personalized results so you can compare yourself with other developers.