entrypoint


Nameentrypoint JSON
Version 2.1.0 PyPI version JSON
download
home_pagehttps://github.com/nekitdev/entrypoint
SummaryDecorated functions as entry points.
upload_time2024-06-16 16:07:55
maintainerNone
docs_urlNone
authornekitdev
requires_python>=3.8
licenseMIT
keywords python entrypoint entry
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # `entrypoint`

[![License][License Badge]][License]
[![Version][Version Badge]][Package]
[![Downloads][Downloads Badge]][Package]
[![Discord][Discord Badge]][Discord]

[![Documentation][Documentation Badge]][Documentation]
[![Check][Check Badge]][Actions]
[![Test][Test Badge]][Actions]
[![Coverage][Coverage Badge]][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:

```console
$ pip install entrypoint
```

Alternatively, the library can be installed from source:

```console
$ 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:

```console
$ poetry add entrypoint
```

Or by directly specifying it in the configuration like so:

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

Alternatively, you can add it directly from the source:

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

## Examples

### Decorated

Declare the `main` function as an *entry point*:

```python
from entrypoint import entrypoint

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

Run the script directly from the console:

```console
$ python file.py
Hello, world!
```

When importing the module, `main` does not get called:

```python
>>> import file
>>> # no output
```

### Note

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

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

print("<- outside")
```

```console
$ python note.py
-> in main
<- outside
```

### Direct

It is possible to run `main` directly:

```python
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*:

```python
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:

```python
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.

```python
@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][Documentation].

## Support

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

## Changelog

You can find the changelog [here][Changelog].

## Security Policy

You can find the Security Policy of `entrypoint` [here][Security].

## Contributing

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

## License

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

[Email]: mailto:support@nekit.dev

[Discord]: https://nekit.dev/chat

[Actions]: https://github.com/nekitdev/entrypoint/actions

[Changelog]: https://github.com/nekitdev/entrypoint/blob/main/CHANGELOG.md
[Code of Conduct]: https://github.com/nekitdev/entrypoint/blob/main/CODE_OF_CONDUCT.md
[Contributing Guide]: https://github.com/nekitdev/entrypoint/blob/main/CONTRIBUTING.md
[Security]: https://github.com/nekitdev/entrypoint/blob/main/SECURITY.md

[License]: https://github.com/nekitdev/entrypoint/blob/main/LICENSE

[Package]: https://pypi.org/project/entrypoint
[Coverage]: https://codecov.io/gh/nekitdev/entrypoint
[Documentation]: https://nekitdev.github.io/entrypoint

[Discord Badge]: https://img.shields.io/discord/728012506899021874
[License Badge]: https://img.shields.io/pypi/l/entrypoint
[Version Badge]: https://img.shields.io/pypi/v/entrypoint
[Downloads Badge]: https://img.shields.io/pypi/dm/entrypoint

[Documentation Badge]: https://github.com/nekitdev/entrypoint/workflows/docs/badge.svg
[Check Badge]: https://github.com/nekitdev/entrypoint/workflows/check/badge.svg
[Test Badge]: https://github.com/nekitdev/entrypoint/workflows/test/badge.svg
[Coverage Badge]: https://codecov.io/gh/nekitdev/entrypoint/branch/main/graph/badge.svg


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nekitdev/entrypoint",
    "name": "entrypoint",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "python, entrypoint, entry",
    "author": "nekitdev",
    "author_email": "nekit@nekit.dev",
    "download_url": "https://files.pythonhosted.org/packages/01/46/d482b3f96d32640bd342a63c0ac19f3187c328011fb281ba302c90ee332c/entrypoint-2.1.0.tar.gz",
    "platform": null,
    "description": "# `entrypoint`\n\n[![License][License Badge]][License]\n[![Version][Version Badge]][Package]\n[![Downloads][Downloads Badge]][Package]\n[![Discord][Discord Badge]][Discord]\n\n[![Documentation][Documentation Badge]][Documentation]\n[![Check][Check Badge]][Actions]\n[![Test][Test Badge]][Actions]\n[![Coverage][Coverage Badge]][Coverage]\n\n> *Decorated functions as entry points.*\n\nIn python, an *entry point* can be thought of as an explicit function\nthat gets called when the script is run directly from the console.\n\nDefining an entry point requires some boilerplate code, which is\nabstracted away by this library.\n\n## Installing\n\n**Python 3.8 or above is required.**\n\n### pip\n\nInstalling the library with `pip` is quite simple:\n\n```console\n$ pip install entrypoint\n```\n\nAlternatively, the library can be installed from source:\n\n```console\n$ git clone https://github.com/nekitdev/entrypoint.git\n$ cd entrypoint\n$ python -m pip install .\n```\n\n### poetry\n\nYou can add `entrypoint` as a dependency with the following command:\n\n```console\n$ poetry add entrypoint\n```\n\nOr by directly specifying it in the configuration like so:\n\n```toml\n[tool.poetry.dependencies]\nentrypoint = \"^2.1.0\"\n```\n\nAlternatively, you can add it directly from the source:\n\n```toml\n[tool.poetry.dependencies.entrypoint]\ngit = \"https://github.com/nekitdev/entrypoint.git\"\n```\n\n## Examples\n\n### Decorated\n\nDeclare the `main` function as an *entry point*:\n\n```python\nfrom entrypoint import entrypoint\n\n@entrypoint(__name__)\ndef main() -> None:\n    print(\"Hello, world!\")\n```\n\nRun the script directly from the console:\n\n```console\n$ python file.py\nHello, world!\n```\n\nWhen importing the module, `main` does not get called:\n\n```python\n>>> import file\n>>> # no output\n```\n\n### Note\n\nNote that `main` gets called **immediately, before any code below can be executed**.\n\n```python\n@entrypoint(__name__)\ndef main() -> None:\n    print(\"-> in main\")\n\nprint(\"<- outside\")\n```\n\n```console\n$ python note.py\n-> in main\n<- outside\n```\n\n### Direct\n\nIt is possible to run `main` directly:\n\n```python\nentrypoint(__name__).call(main)\n```\n\nThis method allows to take control over where and when the function gets called.\n\n### Check\n\n`entrypoint` also provides `is_main` function that resembles\nthe common (and de-facto standard) way of implementing *entry points*:\n\n```python\nfrom entrypoint import is_main\n\nif is_main(__name__):\n    print(\"Hello, world!\")\n```\n\n### Return\n\n`entrypoint` expects `main` functions to not have arguments and return nothing.\nEven though this is *not* checked at *runtime*, returning from `main` will cause\n*type-checkers* to *error*!\n\n### Async\n\n`entrypoint` does not provide any specific functionality to run async functions.\n\nInstead, you can specify, for example, a `main` function that runs its `async_main` counterpart:\n\n```python\nfrom async_extensions import run\n\nasync def async_main() -> None:\n    print(\"Hello, world!\")\n\n@entrypoint(__name__)\ndef main() -> None:\n    run(async_main())\n```\n\n### Implicit\n\nIn case an entry point gets created without `__name__` given, it is going to attempt\nto fetch the module from the `main` function provided.\n\n```python\n@entrypoint()\ndef main() -> None:\n    print(\"Hello, world!\")\n```\n\nPlease keep in mind that calling functions defined outside the `__main__` module\nwill not work with implicit fetching.\n\n## Documentation\n\nYou can find the documentation [here][Documentation].\n\n## Support\n\nIf you need support with the library, you can send an [email][Email]\nor refer to the official [Discord server][Discord].\n\n## Changelog\n\nYou can find the changelog [here][Changelog].\n\n## Security Policy\n\nYou can find the Security Policy of `entrypoint` [here][Security].\n\n## Contributing\n\nIf you are interested in contributing to `entrypoint`, make sure to take a look at the\n[Contributing Guide][Contributing Guide], as well as the [Code of Conduct][Code of Conduct].\n\n## License\n\n`entrypoint` is licensed under the MIT License terms. See [License][License] for details.\n\n[Email]: mailto:support@nekit.dev\n\n[Discord]: https://nekit.dev/chat\n\n[Actions]: https://github.com/nekitdev/entrypoint/actions\n\n[Changelog]: https://github.com/nekitdev/entrypoint/blob/main/CHANGELOG.md\n[Code of Conduct]: https://github.com/nekitdev/entrypoint/blob/main/CODE_OF_CONDUCT.md\n[Contributing Guide]: https://github.com/nekitdev/entrypoint/blob/main/CONTRIBUTING.md\n[Security]: https://github.com/nekitdev/entrypoint/blob/main/SECURITY.md\n\n[License]: https://github.com/nekitdev/entrypoint/blob/main/LICENSE\n\n[Package]: https://pypi.org/project/entrypoint\n[Coverage]: https://codecov.io/gh/nekitdev/entrypoint\n[Documentation]: https://nekitdev.github.io/entrypoint\n\n[Discord Badge]: https://img.shields.io/discord/728012506899021874\n[License Badge]: https://img.shields.io/pypi/l/entrypoint\n[Version Badge]: https://img.shields.io/pypi/v/entrypoint\n[Downloads Badge]: https://img.shields.io/pypi/dm/entrypoint\n\n[Documentation Badge]: https://github.com/nekitdev/entrypoint/workflows/docs/badge.svg\n[Check Badge]: https://github.com/nekitdev/entrypoint/workflows/check/badge.svg\n[Test Badge]: https://github.com/nekitdev/entrypoint/workflows/test/badge.svg\n[Coverage Badge]: https://codecov.io/gh/nekitdev/entrypoint/branch/main/graph/badge.svg\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Decorated functions as entry points.",
    "version": "2.1.0",
    "project_urls": {
        "Chat": "https://nekit.dev/chat",
        "Documentation": "https://nekitdev.github.io/entrypoint",
        "Funding": "https://nekit.dev/funding",
        "Homepage": "https://github.com/nekitdev/entrypoint",
        "Issues": "https://github.com/nekitdev/entrypoint/issues",
        "Repository": "https://github.com/nekitdev/entrypoint"
    },
    "split_keywords": [
        "python",
        " entrypoint",
        " entry"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3115602cdd6aa1c1ab54e1a58428775c07105942d9337acb1244d8ea47864b7f",
                "md5": "24c9fa1b36367ad90e2c45bf1a947ae0",
                "sha256": "46a5b4c8d88964267caf81e30576b9a2776d51fc5521a05b0c89b8f2b7b7412b"
            },
            "downloads": -1,
            "filename": "entrypoint-2.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "24c9fa1b36367ad90e2c45bf1a947ae0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5362,
            "upload_time": "2024-06-16T16:07:54",
            "upload_time_iso_8601": "2024-06-16T16:07:54.702248Z",
            "url": "https://files.pythonhosted.org/packages/31/15/602cdd6aa1c1ab54e1a58428775c07105942d9337acb1244d8ea47864b7f/entrypoint-2.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0146d482b3f96d32640bd342a63c0ac19f3187c328011fb281ba302c90ee332c",
                "md5": "fa9c7a34db3dfb0dd7d9810dcfbc9e1e",
                "sha256": "c0f22893cd24815082514c59ebd0d21118228edbfa033b1b28ff7d0f47552093"
            },
            "downloads": -1,
            "filename": "entrypoint-2.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fa9c7a34db3dfb0dd7d9810dcfbc9e1e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4928,
            "upload_time": "2024-06-16T16:07:55",
            "upload_time_iso_8601": "2024-06-16T16:07:55.760193Z",
            "url": "https://files.pythonhosted.org/packages/01/46/d482b3f96d32640bd342a63c0ac19f3187c328011fb281ba302c90ee332c/entrypoint-2.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-16 16:07:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nekitdev",
    "github_project": "entrypoint",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "entrypoint"
}
        
Elapsed time: 0.39664s