Getting Started¶
This section covers the basics of getting Pynenc installed and running in your environment.
Installation¶
Installing Pynenc is straightforward and can be accomplished using pip. Simply run the following command in your terminal:
pip install pynenc
This command will download and install Pynenc along with its necessary dependencies. Once the installation is complete, you are ready to start using Pynenc in your Python projects.
For more detailed instructions and advanced installation options, refer to the Installation section in the Pynenc Documentation.
Quick Start¶
To get a quick feel of Pynenc, here’s a basic example of creating and executing a distributed task.
Define a Task: Create a file named
tasks.pyand define a simple addition task:from pynenc import Pynenc app = Pynenc() @app.task def add(x: int, y: int) -> int: add.logger.info(f"{add.task_id=} Adding {x} + {y}") return x + y
Start Your Runner or Run Synchronously:
Before executing the task, decide if you want to run it asynchronously with a runner or synchronously for testing or development purposes.
Asynchronously: Start a runner in a separate terminal or script:
pynenc --app=tasks.app runner start
Check for the basic_redis_example
Synchronously: For test or local demonstration, to try synchronous execution, you can set the environment variable
PYNENC__DEV_MODE_FORCE_SYNC_TASKS=Trueto force tasks to run in the same thread.
Execute the Task:
result = add(1, 2).result print(result) # This will output the result of 1 + 2
For a more comprehensive guide on setting up and running this example, visit our Basic Redis Example on GitHub.
Important
Note that in Pynenc, tasks cannot be defined in Python modules intended to run as standalone scripts
(where __name__ is set to "__main__"). This includes modules executed directly or using the
python -m module command. To learn more about this limitation and its implications, refer to the
Frequently Asked Questions or the detailed explanation in the Usage Guide.
Requirements¶
To effectively use Pynenc in a distributed system, the primary requirement is:
Redis: Currently, Pynenc requires a Redis server for distributed task management. Make sure Redis is installed and running in your environment.
Future Updates:
Development plans include extending support to additional databases and message queues to broaden Pynenc’s compatibility in various distributed systems.