A Railway pattern based operation package
Project description
Operation
Railway Oriented Programming implementation for Python.
Basic Usage
- Create a class that inherit from
Operation, withphasesmethod:
from operation import Operation
class SomeOperation(Operation):
def phases(self):
return [
'phase_one',
'phase_two',
'phase_three'
]
def phase_one(self):
self.options['option_for_second_phase'] = True
def phase_two(self):
if 'option_for_second_phase' in self.options:
return 'an option got passed from first phase, cool!'
def phase_three(self):
self.options['reached_third_phase'] = True
- in the operation manager, use
SomeOperation(options).run(), whereoptionsare the input to the operation flow.
Example
For example, if you create an operation that first connects to a database, then fetches the a document by an id, validates it, and finally send a post request of the entry's user_id, it can look like this:
import requests
from pymongo import MongoClient
from operation import Operation
class RetrieveDataAndPost(Operation):
def phases(self):
return [
'connect_to_mongo',
'fetch_document',
'validate_document',
'post_results'
]
def connect_to_mongo(self):
self.options['albums_collection'] = MongoClient('<MongoDB_URL>').albums
def fetch_document(self):
album_id = self.options.get('album_id')
self.options['album'] = self.options['albums_collection'].find_one({ 'id': album_id })
def validate_document(self):
if 'artist_name' not in self.options['album']:
self.fail_operation()
def post_results(self):
selected_artist = self.options.get('album').get('artist_name')
requests.post('<Artists_Service_URL>', data={'selected_artist': selected_artist})
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
operation-0.0.2.tar.gz
(3.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file operation-0.0.2.tar.gz.
File metadata
- Download URL: operation-0.0.2.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ed235bd719febf187a611ce3025c2575e7ca225c7480702b1262697bdf4960c
|
|
| MD5 |
11292a1f4a950f6a76cf26e9b8609a62
|
|
| BLAKE2b-256 |
93c5f161cee3f50efc0ee216fe63b7f8a7960ef501f47438783e12a16c1512f0
|
File details
Details for the file operation-0.0.2-py3-none-any.whl.
File metadata
- Download URL: operation-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b27765da86215536b8a09f955d61a5ec376adc32396729571daf9528d38947ef
|
|
| MD5 |
89414d03416d646e12a3ca5fac6a4861
|
|
| BLAKE2b-256 |
5e0b9dc36f911304a04a26bacc6c2c93b123f2cd2957484d1afcf1fbdf2fa2cf
|