This repository contains examples of using Effect. They demonstrate basic use of Effect to isolate side-effects from code, but also to provide alternative implementations of those side-effecting actions without requiring changes to core application logic.
This package isn't meant to be installed, but rather just copied to your local
dev environment and tinkered with. To install dependencies use pip install -r requirements.txt
.
The ehttp
directory contains a very simple HTTPRequest
intent and
performers using common HTTP client libraries:
requests and
treq.
treq is a Twisted-based library, showing that Effect can be used (with the
additional txeffect package) to
write generic code that can use either Twisted-based asynchronous IO or normal
blocking IO. Other asynchronous frameworks (such as Python 3's asyncio
)
could also be used in this way.
The readline_intent.py
file has a simple ReadLine
intent that uses raw_input
(or input
in Py3) to prompt the user for input.
The github
directory contains a simple application that lets the user input a
GitHub username and prints out a list of all repositories that that user has
access to. It depends on the ehttp
and readline_intent
modules.
Note that if you run this example too rapidly, GitHub might temporarily block your IP from making anonymous API requests for some short period of time.
There are two entrypoints into the example:
github.sync_main
and
github.twisted_main
. sync_main
does
typical blocking IO, and twisted_main
uses asynchronous IO. Note that the
vast majority of the code doesn't need to care about this difference; the only
part that cares about it is the *_main.py
files. All of the logic in
core.py
is generic.
To run them:
python -m github.sync_main
or
python -m github.twisted_main
Note that the twisted example does not run on Python 3, but all other examples do.
The github example app has unit tests in
test_core.py
. They can be discovered and run simply by
running py.test
in the top-level directory.