question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic endpoint function signature

See original GitHub issue

Hi,

Is it possible to create an endpoint from a dict of parameters, something like:


params = {"param1": int, "param2": str }

@app.get("/root")
def root(**params):
  pass

?

(the above doesn’t work, the docs for example say that root takes one parameter called params)

Thank you! Marco

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
marcovccommented, Dec 15, 2020

Here’s a solution with @Mause suggestion:

from makefun import with_signature

params_str = ",".join(f"{k}: {v}" for k, v in run_time_params)

class Args:
  @with_signature(f"__init__(self, {params_str}"):
  def fn(*args, **kwargs):
    pass

@app.get("/root")
def root(args: Args = Depends()):
  pass

Thanks both!

1reaction
Mausecommented, Dec 15, 2020

I suggest you look at the makefun library, it works quite well for this use

https://pypi.org/project/makefun/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic function signature in help() - python
This works so far. However, I would like to set the method signature shown with help(proxy) dynamically. It would increase the user interface ......
Read more >
Support for Dynamic REST Endpoints
The REST Adapter enables you to dynamically change the (invoke) outbound endpoint configuration. This feature is useful in the following scenarios:
Read more >
Dynamic Outlook Email Signature Using with Intune ...
In this blog post we will be get familiar with a somewhat novel idea that proactive remediation's can be used for. Which, as...
Read more >
Routing & Input
An incoming HTTP request must be “routed” to one or more R functions. Plumber has two distinct families of functions that it handles:...
Read more >
Dynamic Custom Apps | Help Scout Developers
Dynamic Apps require two things in order to function properly: ... Help Scout uses this secret key to generate a signature for each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found