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.

[FEATURE] Adding Typer to custom package using entry points

See original GitHub issue

Wuhuu finally started using Typer and very excited about it.

I went ahead and used the most simple example

import typer

def main(name: str):
    typer.echo(f"Hello {name}")


if __name__ == "__main__":
    typer.run(main)

which works just fine obviously. But I’d like to expose my custom package with CLI using Typer so I made a setup.py with

from setuptools import setup

setup(
    name="my_package",
    entry_points={
        "console_scripts": ["hello = my_package.cli:main"],
    },
)

Then I can call the command using hello in a terminal BUT it doesn’t carry over any positional arguments. Maybe you could add some about entry points integration in the docs?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
tiangolocommented, Mar 19, 2020

Thanks for the discussion here everyone!

If you have simple scripts and you want to get completion, you can now use Typer CLI to run your Typer scripts without having to install anything.

If you want to create a package, there’s a new guide Building a Package 🎉 .

3reactions
maartenqcommented, Dec 22, 2021

The entry_point should point so something executing typer.run. Something like this would do:

import typer

def main(name: str):
    typer.echo(f"Hello {name}")

def run():
    typer.run(main)

if __name__ == "__main__":
    run()
from setuptools import setup

setup(
    name="my_package",
    entry_points={
        "console_scripts": ["hello = my_package.cli:run"],
    },
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Entry points specification - Python Packaging User Guide
Entry points are a mechanism for an installed distribution to advertise components it provides to be discovered and used by other code. For...
Read more >
Python Entry Points Explained - Amir Rachum's Blog
I'm going to show you how to use entry points as a modular plug-in architecture. This is super useful if you want to...
Read more >
Entry Points - webpack
We will show you the ways you can configure the entry property, in addition to ... dependOn : The entry points that the...
Read more >
Explain Python entry points? - setuptools - Stack Overflow
Entry points are useful for allowing one package do use plugins that are in another package. For instance, Ian Bicking's Paste project uses ......
Read more >
Creating Secondary Entry Points for your Angular Library
Developing an Angular Library is easier than ever nowadays since the release of Angular Library feature (from Angular 7).
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