Skip to main content

entrypoint

License Version Downloads Discord

Documentation Check Test Coverage

Decorated functions as entry points.

In python, an entry point can be thought of as an explicit function that gets called when the script is run directly from the console.

Defining an entry point requires some boilerplate code, which is abstracted away by this library.

Installing

Python 3.8 or above is required.

pip

Installing the library with pip is quite simple:

$ pip install entrypoint

Alternatively, the library can be installed from source:

$ git clone https://github.com/nekitdev/entrypoint.git
$ cd entrypoint
$ python -m pip install .

poetry

You can add entrypoint as a dependency with the following command:

$ poetry add entrypoint

Or by directly specifying it in the configuration like so:

[tool.poetry.dependencies]
entrypoint = "^2.1.0"

Alternatively, you can add it directly from the source:

[tool.poetry.dependencies.entrypoint]
git = "https://github.com/nekitdev/entrypoint.git"

Examples

Decorated

Declare the main function as an entry point:

from entrypoint import entrypoint

@entrypoint(__name__)
def main() -> None:
    print("Hello, world!")

Run the script directly from the console:

$ python file.py
Hello, world!

When importing the module, main does not get called:

>>> import file
>>> # no output

Note

Note that main gets called immediately, before any code below can be executed.

@entrypoint(__name__)
def main() -> None:
    print("-> in main")

print("<- outside")
$ python note.py
-> in main
<- outside

Direct

It is possible to run main directly:

entrypoint(__name__).call(main)

This method allows to take control over where and when the function gets called.

Check

entrypoint also provides is_main function that resembles the common (and de-facto standard) way of implementing entry points:

from entrypoint import is_main

if is_main(__name__):
    print("Hello, world!")

Return

entrypoint expects main functions to not have arguments and return nothing. Even though this is not checked at runtime, returning from main will cause type-checkers to error!

Async

entrypoint does not provide any specific functionality to run async functions.

Instead, you can specify, for example, a main function that runs its async_main counterpart:

from async_extensions import run

async def async_main() -> None:
    print("Hello, world!")

@entrypoint(__name__)
def main() -> None:
    run(async_main())

Implicit

In case an entry point gets created without __name__ given, it is going to attempt to fetch the module from the main function provided.

@entrypoint()
def main() -> None:
    print("Hello, world!")

Please keep in mind that calling functions defined outside the __main__ module will not work with implicit fetching.

Documentation

You can find the documentation here.

Support

If you need support with the library, you can send an email or refer to the official Discord server.

Changelog

You can find the changelog here.

Security Policy

You can find the Security Policy of entrypoint here.

Contributing

If you are interested in contributing to entrypoint, make sure to take a look at the Contributing Guide, as well as the Code of Conduct.

License

entrypoint is licensed under the MIT License terms. See License for details.

Metadata

Release files for entrypoint 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for entrypoint 2.1.0
File Size Uploaded
entrypoint-2.1.0.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for entrypoint 2.1.0
File Interpreter ABI Platform
entrypoint-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 kB

Release files / entrypoint-2.1.0.tar.gz

Download URL entrypoint-2.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c0f22893cd24815082514c59ebd0d21118228edbfa033b1b28ff7d0f47552093
BLAKE2b-256 checksum
How to use checksums
0146d482b3f96d32640bd342a63c0ac19f3187c328011fb281ba302c90ee332c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.4

Release files / entrypoint-2.1.0-py3-none-any.whl

Download URL entrypoint-2.1.0-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46a5b4c8d88964267caf81e30576b9a2776d51fc5521a05b0c89b8f2b7b7412b
BLAKE2b-256 checksum
How to use checksums
3115602cdd6aa1c1ab54e1a58428775c07105942d9337acb1244d8ea47864b7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page