Skip to main content

Yet Another Python Sequencer

Project description

yapyseq

Yet Another Python Sequencer

Item master dev
CI status Build Status Build Status
version Pypi N/A

Overview

If you have a bunch of Python functions in a bunch of files, which can be called in various orders in function of the need, you have two choices:

  • Call these functions in classic python scripts, ordering the calls with Python statements. You have to write from scratch the conditional structures, the multiprocessing management if necessary, and eventually write a lot of code.
  • Use yapyseq to write a sequence. A sequence file has its own syntax, it makes references to Python functions that must be called. The calls, the conditional transitions between them, the multiprocessing, the logging, all of these things are automatically managed by yapyseq without writing a single line of Python code.

yapyseq principle

Installation

yapyseq is on the Pypi server. To install it, you can use pip:

pip install yapyseq

Quick-start

Let's assume that you have a project in the directory project/ with a sub-directory project/functions containing some Python files like project/functions/hello.py, and some functions like the following ones:

import os

def hello(name):
    print('Hello {}!'.format(name))

def list_path(path):
    print(os.listdir(path))

Now create a sequence file anywhere, for instance project/my_sequence.yaml. Here is the content of a sequence to call list_path, and if no exception has been raised then call hello:

quickstart sequence

sequence:

  nodes:
    - id: 0
      type: start
      transitions:
        - target: 1

    - id: 1
      type: function
      function: list_path
      arguments:
        path: "/tmp/"
      transitions:
        - target: 2
          condition: not results[1].exception
        - target: 3
          condition: results[1].exception

    - id: 2
      type: function
      function: hello
      arguments:
        name: "John"
      transitions:
        - target: 3

    - id: 3
      type: stop

To run the sequence in command line, run the following command in a terminal:

yapyseq run Project/my_sequence.yaml Project/Functions

The command yapyseq run takes as arguments: the path to the sequence file and the path to the directory containing the Python functions.

After pressing enter, you should see the output of list_path() and hello() in the terminal.

To run the sequence using yapyseq as a Python module, run the following code:

from yapyseq import SequenceRunner

sr = SequenceRunner('Project/my_sequence.yaml', 'Project/Functions')
sr.run()

Of course, for an example that simple, making a sequence with yapyseq requires more work than calling the functions in a simple Python script. But it is just an example to start, and yapyseq will be much more useful in more complex situations. Please read the next sections to learn more.

More details for users

To get more details about how to use yapyseq, please read the user documentation.

Contributions

Contributions are welcome from anyone ! To have a better understanding of the internal structure of yapyseq and to know more about the integration process, please read the developer documentation.

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

yapyseq-1.1.0.tar.gz (22.4 kB view details)

Uploaded Source

File details

Details for the file yapyseq-1.1.0.tar.gz.

File metadata

  • Download URL: yapyseq-1.1.0.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for yapyseq-1.1.0.tar.gz
Algorithm Hash digest
SHA256 59c9395fcb86076201eaf9312000d878f3e98a3d039adb316e981de6d1029f3d
MD5 514fc1f3a85e8b208acec458780bbcba
BLAKE2b-256 3a3d6ad439faffe4f9494bfc1023d1529a21ea68e422f199293bfc3769aaada8

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