Giter Site home page Giter Site logo

priyanshu-panwar / fastapi-utilities Goto Github PK

View Code? Open in Web Editor NEW
29.0 29.0 0.0 139 KB

๐ŸŽจโšก๏ธ๐Ÿ”ฅ Reusable Utilities for FastAPI

Home Page: https://youtu.be/ZIggeTU8JhQ?si=SO1B0Is0RdXDkbCa

License: MIT License

Python 100.00%
cli fastapi fastapi-boilerplate fastapi-cli fastapi-template fastapi-utilities fastapi-utils

fastapi-utilities's Introduction

Welcome to my GitHub profile!

I'm Priyanshu, a software engineer passionate about building innovative solutions that make a difference. Currently, I'm part of the dynamic team at Blink Health, where we're revolutionizing healthcare technology to improve access and affordability for all.

๐Ÿ”ง Technologies & Tools

  • Languages: C++, Java, Python, JavaScript
  • Frameworks: FastAPI, React, React Native, Next.js, Django, Spring Boot

๐Ÿš€ Experience

  • Blink Health (Current)
  • Samsung
  • Amazon

๐Ÿ“ซ Let's Connect

fastapi-utilities's People

Contributors

dependabot[bot] avatar priyanshu-panwar 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

Watchers

 avatar  avatar  avatar

fastapi-utilities's Issues

TypeError: 'module' object is not callable for repeat methods

The examples on how to use the repeat annotations seem to be broken, as repeat.repeat_every and repeat.repeat_at are modules, not objects.

Steps to replicate

  1. Set up a new venv for testing:
mkdir -p test_dir; cd test_dir/
python -m venv .venv
source .venv/bin/activate
pip install fastapi fastapi_utilities
  1. Create a file called main.py with the example code from the README:
from fastapi import FastAPI
from contextlib import asynccontextmanager
from fastapi_utilities.repeat import repeat_every, repeat_at

@asynccontextmanager
async def lifespan(app: FastAPI):
    # --- startup ---
    await test()
    test2()
    yield
    # --- shutdown ---

app = FastAPI(lifespan=lifespan)

# Repeat Every Example
@repeat_every(seconds=2)
async def test():
    print("test")

# Repeat At Example
@repeat_at(cron="* * * * *")
def test2():
    print("test2")
  1. Run the test app:
uvicorn main:app --reload
  1. You will get the following error:
INFO:     Will watch for changes in these directories: ['/some/path/test_dir']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [12607] using WatchFiles
Process SpawnProcess-1:
Traceback (most recent call last):
  File "/some/path/.pyenv/versions/3.12.1/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/some/path/.pyenv/versions/3.12.1/lib/python3.12/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/some/path/test_dir/.venv/lib/python3.12/site-packages/uvicorn/_subprocess.py", line 78, in subprocess_started
    target(sockets=sockets)
  File "/some/path/test_dir/.venv/lib/python3.12/site-packages/uvicorn/server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/some/path/.pyenv/versions/3.12.1/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/some/path/.pyenv/versions/3.12.1/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/some/path/test_dir/.venv/lib/python3.12/site-packages/uvicorn/server.py", line 69, in serve
    await self._serve(sockets)
  File "/some/path/test_dir/.venv/lib/python3.12/site-packages/uvicorn/server.py", line 76, in _serve
    config.load()
  File "/some/path/test_dir/.venv/lib/python3.12/site-packages/uvicorn/config.py", line 433, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/some/path/test_dir/.venv/lib/python3.12/site-packages/uvicorn/importer.py", line 19, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/some/path/.pyenv/versions/3.12.1/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 994, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/some/path/test_dir/main.py", line 16, in <module>
    @repeat_every(seconds=2)
     ^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'module' object is not callable

Workaround

I was able to get the code to work by adding an extra level to the import statements, so I think this may be an issue with how the repeat module is structured or something.

This code works:

from fastapi import FastAPI
from contextlib import asynccontextmanager
# from fastapi_utilities.repeat import repeat_every, repeat_at # <-- Commented out
from fastapi_utilities.repeat.repeat_at import repeat_at       # <-- Changed this
from fastapi_utilities.repeat.repeat_every import repeat_every # <-- Changed this
@asynccontextmanager
async def lifespan(app: FastAPI):
    # --- startup ---
    await test()
    test2()
    yield
    # --- shutdown ---

app = FastAPI(lifespan=lifespan)

# Repeat Every Example
@repeat_every(seconds=2)
async def test():
    print("test")

# Repeat At Example
@repeat_at(cron="* * * * *")
def test2():
    print("test2")

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.