Skip to main content

Asynchronous framework for managing asynchronous execution of independent tasks

Project description

taskorbit-logo

TaskOrbit: Effortless Tasking

An asynchronous framework for Python with efficient task pooling that provides simple and flexible management of asynchronous execution of independent tasks.

Status PyPI Python Python Python

Taskorbit

Taskorbit is an asynchronous framework for managing a queue of asynchronous tasks. Inspired by ideas from Celery, Taskiq, Propan and Aiogram. This framework is based on message brokers. Currently, there is only support for NATS JetStream. An expansion is planned for the future.

The framework allows you to create a powerful service for processing any tasks of any complexity in a short time. Entry is minimal, the development was oriented on beginners in the world of bot building and microservices development.

We can say simply - it is an improved version of Celery, Taskiq, Propan in the style of Aiogram. The differences are in specific requirements. It is important to choose technologies carefully to achieve optimal results.

Documentation is currently being developed and will be available at: https://morington.github.io/taskorbit/

Install

Use the pip tool to install the framework:

pip install taskorbit

Currently, with support for the NATS message broker only, variable installation with the broker is not supported. The library will install the necessary dependencies if required.

Taskorbit currently includes:

  • magic_filter - a handy way to enable dynamic signatures, created by the Aiogram developers.
  • ormsgpack - a quick way to serialize data.
  • nats-py - a standard message broker.

Quick start

You can read the full example on the repository page: https://github.com/morington/taskorbit/blob/main/examples/base_example.py.

Create a broker object, distpecker object in your asynchronous function, load the configuration and start receiving messages!

# For the example I will not use routers, the dispatcher inherits from routers so can also integrate handlers.
# DON'T DO THIS! USE taskorbit.dispatching.Router !
dp = Dispatcher(max_queue_size=5)


@dp.include_handler(F.metadata.type_event == "Test")
async def handler_test(metadata: Metadata) -> None:
    logger.info(f"Handler got the message! Task-{metadata.uuid}")


async def main():
    broker = await nats_broker(
        {
            "url": "nats://localhost:4222",
            "stream": "STREAM_NAME",
            "subject": "STREAM_NAME.SUBJECT",
            "durable": "DURABLE",
        }
    )
	
    await broker.include_dispatcher(dp)


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

Models metadata

At the moment, development is underway on out-of-the-box custom message models. Please wait, the standard Metadata model is currently available for both service messages and task data messages:

class Message(BaseType):
    uuid: str
    type_event: str
    data: Optional[dict] = None


@dataclass
class ServiceMessage(BaseType):
    uuid: str
    command: Commands

Sending messages

You can send messages to stream using the pub method:

# Data messages for tasks:
await broker.pub({"uuid": _uuuid, "type_event": "TEST_CLASS", "data": {"some_data": 123}}))

# Service messages to work with tasks:
await broker.pub({"uuid": _uuuid, "command": Commands.GET_STATUS})

The framework also supports outer-middlewares and inner-middlewares. Middlewares fully support context managers throughout task processing.

Currently, the Filters classes are disabled. Under testing.

Please don't forget to refer to EXAMPLES in the repository structure for help with the framework. Stable examples that have been tested are posted there.

License:

Taskorbit is distributed under the MIT license. Details can be found in the LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

taskorbit-0.1.1a0.tar.gz (168.0 kB view details)

Uploaded Source

Built Distribution

taskorbit-0.1.1a0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file taskorbit-0.1.1a0.tar.gz.

File metadata

  • Download URL: taskorbit-0.1.1a0.tar.gz
  • Upload date:
  • Size: 168.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for taskorbit-0.1.1a0.tar.gz
Algorithm Hash digest
SHA256 2a8b8d147e6d0ddaac529fadb20f604fe4b1a4089d25336f60d2947d0efcb513
MD5 e406f4ecd1500b5f8e41bfaf67b6762c
BLAKE2b-256 cbcccba67394085bce9cec7ac6578ac60d91fbf0f0abca65ea9d1dc15d3046c6

See more details on using hashes here.

File details

Details for the file taskorbit-0.1.1a0-py3-none-any.whl.

File metadata

  • Download URL: taskorbit-0.1.1a0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for taskorbit-0.1.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce30dff0bf013155672ea12639e7e09d9d4af9f61a563e56de9ce84bf0280f59
MD5 935c2c269aae3990cd4b8cf2266e6e73
BLAKE2b-256 674a7eedd50ff6f69e47f1064e1f77d36f63b4c188059d064cc3f3caea4d3ad5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page