Giter VIP home page Giter VIP logo

panther's Introduction

PyPI PyVersion codecov Downloads license

Panther

Is A Fast & Friendly Web Framework For Building Async APIs With Python 3.10+

logo

๐Ÿ“š Full Documentation: PantherPy.GitHub.io


Why Use Panther ?

  • Document-oriented Databases ODM (PantherDB, MongoDB)
  • Built-in Websocket Support
  • Cache APIs (In Memory, In Redis)
  • Built-in Authentication Classes (Customizable)
  • Built-in Permission Classes (Customizable)
  • Handle Custom Middlewares
  • Handle Custom Throttling
  • Visual API Monitoring (In Terminal)

Supported by

jetbrains

Benchmark

Framework Throughput (Request/Second)
Blacksheep 5,339
Muffin 5,320
Panther 5,112
Sanic 3,660
FastAPI 3,260
Tornado 2,081
Bottle 2,045
Django 821
Flask 749

More Detail: https://GitHub.com/PantherPy/frameworks-benchmark


Installation

  • 1. Create a Virtual Environment
    $ python3 -m venv .venv
  • 2. Active The Environment * Linux & Mac
    $ source .venv/bin/activate
    * Windows
    $ .\.venv\Scripts\activate
  • 3. Install Panther - โฌ‡ Normal Installation
    $ pip install panther
    - โฌ‡ Include full requirements (MongoDB, JWTAuth, Ruff, Redis, bpython)
    $ pip install panther[full]

Usage

  • Create Project

    $ panther create
  • Run Project

    $ panther run --reload

    * Panther uses Uvicorn as ASGI (Asynchronous Server Gateway Interface) but you can run the project with Granian, daphne or any ASGI server too

  • Monitoring Requests

    $ panther monitor 
  • Python Shell

    $ panther shell

Single-File Structure Example

  • Create main.py

    from datetime import datetime, timedelta
    
    from panther import version, status, Panther
    from panther.app import API
    from panther.request import Request
    from panther.response import Response
    from panther.throttling import Throttling
    
    InfoThrottling = Throttling(rate=5, duration=timedelta(minutes=1))
    
    
    @API()
    async def hello_world():
        return {'detail': 'Hello World'}
    
    
    @API(cache=True, throttling=InfoThrottling)
    async def info(request: Request):
        data = {
            'panther_version': version(),
            'datetime_now': datetime.now().isoformat(),
            'user_agent': request.headers.user_agent
        }
        return Response(data=data, status_code=status.HTTP_202_ACCEPTED)
    
    
    url_routing = {
        '': hello_world,
        'info': info,
    }
    
    app = Panther(__name__, configs=__name__, urls=url_routing)
  • Run the project:

    • $ panther run --reload
  • Now you can see these two urls:

Next Step: First CRUD

Real Word Example: Https://GitHub.com/PantherPy/panther-example


Roadmap

roadmap


If you find this project useful, please give it a star โญ๏ธ.

panther's People

Contributors

aka-devoid avatar alirn76 avatar aminiun avatar satyahbp avatar softcysec avatar vahidfathi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

panther's Issues

requirements issue

Describe the bug
A clear and concise description of what the bug is.

Expected behavior
I can't install Panther with pip. I think the problem is that uvloop in the requirements can't be installed for Windows.

Desktop (please complete the following information):

  • OS: windows10

Additional context

(env) E:\PycharmProjects\panther_test_project>pip install panther
Collecting panther
  Obtaining dependency information for panther from https://files.pythonhosted.org/packages/28/5a/92fc7906d6504777b8df2ea0b49d36e4a6d1fac0e512338eb9ccc51242fe/panther-1.7.15-py3-none-any.whl.metadata
  Using cached panther-1.7.15-py3-none-any.whl.metadata (7.8 kB)
Collecting bpython~=0.24 (from panther)
  Using cached bpython-0.24-py3-none-any.whl (194 kB)
Collecting bson~=0.5 (from panther)
  Using cached bson-0.5.10.tar.gz (10 kB)
  Preparing metadata (setup.py) ... done
Collecting httptools~=0.5 (from panther)
  Obtaining dependency information for httptools~=0.5 from https://files.pythonhosted.org/packages/80/e6/158e8d56f6b4d29295cfa244f1e79a65d0987bb3941d36863e7f6e06e3b6/httptools-0.6.0-cp311-cp311-win_amd64.whl.metadata
  Using cached httptools-0.6.0-cp311-cp311-win_amd64.whl.metadata (3.6 kB)
Collecting pantherdb~=1.2 (from panther)
  Obtaining dependency information for pantherdb~=1.2 from https://files.pythonhosted.org/packages/e0/54/1b2055bd59ecc1106ed0dfc27c1eb2c0fe113f629d381ea60ac4d9cb52b2/pantherdb-1.2.7-py3-none-any.whl.metadata
  Using cached pantherdb-1.2.7-py3-none-any.whl.metadata (3.3 kB)
Collecting pydantic~=2.0 (from panther)
  Obtaining dependency information for pydantic~=2.0 from https://files.pythonhosted.org/packages/1f/1a/71b404f9acb44402f5b581ade106e9219d6d83824d50943e630fc0ca12e5/pydantic-2.0.3-py3-none-any.whl.metadata
  Using cached pydantic-2.0.3-py3-none-any.whl.metadata (128 kB)
Collecting redis~=4.5 (from panther)
  Obtaining dependency information for redis~=4.5 from https://files.pythonhosted.org/packages/20/2e/409703d645363352a20c944f5d119bdae3eb3034051a53724a7c5fee12b8/redis-4.6.0-py3-none-any.whl.metadata
  Using cached redis-4.6.0-py3-none-any.whl.metadata (8.3 kB)
Collecting rich~=13.3 (from panther)
  Obtaining dependency information for rich~=13.3 from https://files.pythonhosted.org/packages/fc/1e/482e5eec0b89b593e81d78f819a9412849814e22225842b598908e7ac560/rich-13.4.2-py3-none-any.whl.metadata
  Using cached rich-13.4.2-py3-none-any.whl.metadata (18 kB)
Collecting uvicorn~=0.21 (from panther)
  Obtaining dependency information for uvicorn~=0.21 from https://files.pythonhosted.org/packages/5d/07/b9eac057f7efa56900640a233c1ed63db83568322c6bcbabe98f741d5289/uvicorn-0.23.1-py3-none-any.whl.metadata
  Using cached uvicorn-0.23.1-py3-none-any.whl.metadata (6.2 kB)
Collecting uvloop~=0.17 (from panther)
  Using cached uvloop-0.17.0.tar.gz (2.3 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  ร— python setup.py egg_info did not run successfully.
  โ”‚ exit code: 1
  โ•ฐโ”€> [6 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\Nima\AppData\Local\Temp\pip-install-qlnxjkz5\uvloop_b087e03c273944f18a6a45207d3eb8ef\setup.py", line 8, in <module>
          raise RuntimeError('uvloop does not support Windows at the moment')
      RuntimeError: uvloop does not support Windows at the moment
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

ร— Encountered error while generating package metadata.
โ•ฐโ”€> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Cache return same response for the different query_params

Describe the bug
Cache return same response for the different query_params. the cache_key generator is cause of this bug. in this method the query params does not included.

Expected behavior
cache system must have different response for different query_params.

Can't get it to run/build etc

(venv) tas509@UOY23M080 test % panther create testapp testapp
Creating Your Project: โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– 

Project Created Successfully.
(venv) tas509@UOY23M080 test % ls   
logs	testapp	venv
(venv) tas509@UOY23M080 test % panther run
ERROR:    Error loading ASGI app. Could not import module "main".
(venv) tas509@UOY23M080 test % open .
(venv) tas509@UOY23M080 test % python --version
Python 3.11.3
(venv) tas509@UOY23M080 test % panther run
ERROR:    Error loading ASGI app. Could not import module "main".

Ah, I had to cd into the folder, then run

Panther shell not working on Windows

Describe the bug
I tried running the Panther shell on Command Prompt in windows with the command given in documentation.
The following error was raised:
(panther_test) D:\Python\testing_panther>panther shell Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "C:\Users\test\.conda\envs\panther_test\Scripts\bpython.exe\__main__.py", line 4, in <module> File "C:\Users\test\.conda\envs\panther_test\Lib\site-packages\bpython\curtsies.py", line 10, in <module> import curtsies File "C:\Users\test\.conda\envs\panther_test\Lib\site-packages\curtsies\__init__.py", line 4, in <module> from .window import FullscreenWindow, CursorAwareWindow File "C:\Users\test\.conda\envs\panther_test\Lib\site-packages\curtsies\window.py", line 30, in <module> from .termhelpers import Cbreak File "C:\Users\test\.conda\envs\panther_test\Lib\site-packages\curtsies\termhelpers.py", line 1, in <module> import tty File "C:\Users\test\.conda\envs\panther_test\Lib\tty.py", line 5, in <module> from termios import * ModuleNotFoundError: No module named 'termios'

Expected behavior
Expected a shell to work.

Environment:

  • OS: Windows: 10
  • Python Version: 3.11.5
  • Panther Version: 3.0.1

Additional context
It seems like "termios" doesn't work on Windows, it only works on unix.
I suggest to add a windows alternative.

Set Events Function with Decorator

Describe the feature you'd like
set startup and shutdown events with a decorator, this is a good way to manage more than one function for events.

ModuleNotFoundError: No module named 'C:\\repos\\<API_NAME>\\app'

Describe the bug
Panther suddenly throws ModuleNotFoundError in the middle of development. Project structure hasn't changed only contents per the documentation and my idea and my IDE reports no errors with the project.

Expected behavior
I expect the app module to be found

Desktop (please complete the following information):

  • OS: Windows 10 Enterprise (10.0.19045 N/A Build 19045)
  • Python Version: Python 3.11.4
  • Panther Version: 2.0.0

Additional context
I have tested on windows, linux, vs code, pycharm, vnev and out and basically when I start making substantive changes to the API project the app module suddenly become unfind-able:

main.py

from panther.app import API
from panther.request import Request
from panther.response import Response
from panther import status

from serializers import MFA_Exception_Request_Serializer


@API(input_model=MFA_Exception_Request_Serializer)
async def MfaExceptionsEndpoint(request: Request):

    data: MFA_Exception_Request_Serializer = request.data

    if request.method == 'POST':
        message = f"You have POSTED to MFA Exceptions for device {data.hostname}"
        return Response(data=message, status_code=status.HTTP_200_OK)

    return Response(data="None of that.", status_code=status.HTTP_501_NOT_IMPLEMENTED)

urls.py

from apis import MfaExceptionsEndpoint

urls = {
    'mfa/requested-exceptions/': MfaExceptionsEndpoint,
}

serializers.py

from pydantic import BaseModel


class MFA_Exception_Request_Serializer(BaseModel):
    hostname: str

main.py

from panther import Panther

app = Panther(__name__)

IDE Error

The error seems to come from main.py which literally hasn't even been touched.

PS <REDACTED>> panther run
'clear' is not recognized as an internal or external command,
operable program or batch file.
DEBUG:    | 2023-08-30 11:22:21 | Base directory: <REDACTED>
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Scripts\panther.exe\__main__.py", line 7, in <module>
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\panther\cli\main.py", line 31, in start
    run(args)
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\panther\cli\run_command.py", line 53, in run
    uvicorn.run('main:app', **command)
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\main.py", line 587, in run
    server.run()
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\server.py", line 68, in serve
    config.load()
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\config.py", line 467, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\importer.py", line 24, in import_from_string
    raise exc from None
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<REDACTED>\main.py", line 3, in <module>
    app = Panther(__name__)
          ^^^^^^^^^^^^^^^^^
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\panther\main.py", line 32, in __init__
    self.load_configs()
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\panther\main.py", line 56, in load_configs
    self._collect_models()
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\panther\main.py", line 140, in _collect_models
    klass = import_class(f'{class_path}.models.{n.name}')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\site-packages\panther\_utils.py", line 66, in import_class
    module = importlib.import_module(path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<REDACTED>AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named <REDACTED>'

Is it there?

I tried the install[full] command and got this...

(venv) tas509@UOY23M080 test % pip install panther[full]
zsh: no matches found: panther[full]

doc issue

hi um panther is dead ?
do you want add more doc (in your code too) ?

Porting WebServer to rust with Pyo3

I'm working on a new feature for Panther, I port the webserver to Rust.
with async support. to enhance the performance ...

for this thing I use Hyper crate + TokIO for async handling ...

please, do not close this issue ... I will add PR soon.

Automatic Resource Module Generator?

Describe the feature you'd like
Similar to DRF having a startproject and startapp command for start projects of apps, it would be nice to have this functionality in Panther so I don't have to create these by hand.

Additional context
Is there a PNP for this already and or can anyone give me an idea how hard this would be to implement?

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.