Welcome to Finchan’s documentation!¶
finchan¶
Finchan event process framework with python.
- Free software: Apache License 2.0
- Documentation: https://finchan.readthedocs.io.
Features¶
Do whatever you want with it.
- Event-driven
- Support live trace and backtrack test
- Easy extensionable
- Support Python 3.6+
- Does not support Python 2.x
Installation¶
Stable release¶
To install finchan, run this command in your terminal:
$ pip install finchan
This is the preferred method to install finchan, as it will always install the most recent stable release.
If you don’t have pip installed, this Python installation guide can guide you through the process.
From sources¶
The sources for finchan can be downloaded from the Github repo.
You can either clone the public repository:
$ git clone git://github.com/qytz/finchan
Or download the tarball:
$ curl -OL https://github.com/qytz/finchan/tarball/master
Once you have a copy of the source, you can install it with:
$ python setup.py install
Usage¶
- steps
- optional, write your own
EventSource
extension. - write your own event subscriber
extension
. - configure the running with configure file.
- run
finchan
withfinchan -c finchan.yml -vvvvv
- optional, write your own
The example EventSource
extension
and Subscriber
extension
can be found in
finchan/exts/
and finchan_exts.
system architecture¶
Finchan is a event system framework,
its main modules are Event
, EventSource
, Dispatcher
, Subscribers
, env
and ExtManager
.
concept¶
The Event
is the input manner for finchan
.
The EventSource
is the original input for the system, it simulate the real world’s things to Event
as input.
The Dispatcher
is the engine of the system,
it manage all EventSource
, all event Subscriber
,
and dispath the events generated by EventSource
or Subscriber
, call the Subscriber
’s callback.
The Subscriber
is event subscriber, it subscriber event with a callback function,
when the event occurs, the Dispatcher
dispatch the event and call the callback function.
The Subscriber
can do anything with the callback function, include generate new events.
The env
is global environment for the system,
you can access it just by from finchan.env import env
,
you can access environment variable setted by other modules, or set your own environment variable.
the ExtManager
manage all extensions for finchan
.
Interfaces¶
kvstore¶
kvstore
is persistent storage for finchan,
finchan
framework just specified the interface for kvstore,
the implemention is done by extensions.
EventSource¶
The EventSource
defines the interface to
implent an EventSource, finchan
system include a TimerSource
,
if you need other EventSource, you should write an extension for finchan
,
or check finchan_exts first.
Write an extension for finchan¶
refer Extend finchan.
APIS¶
finchan.event¶
Event implentation
Event¶
-
class
finchan.event.
Event
(env, name, dt=None, expire=0, event_id=None, **kwargs)[source]¶ Event class
Parameters: - name – name of the event
- dt – occur datetime
- expire – expire in second
- event_id – id of the event
- **kwargs – special kwargs for the event, can get by kwargs attribute
can compare less/greater than with other event object by time, equal by event id.
-
id
¶ ID of the event
-
name
¶ Name of the event
-
timestamp
¶ Occur time of the event, in POSIX timestamp format
-
expire
¶ expire expire in seconds after event occur time (timestamp attribute), 0 is no expire.
finchan.interface.event_source¶
finchan.interface.kvstore¶
kvstore Interface, inspired by redis-py.
AbsKvStore¶
-
class
finchan.interface.kvstore.
AbsKvStore
(*args, **kwargs)[source]¶ KV store interface
init the kvstore connection
-
mset
(*args, **kwargs)[source]¶ Sets key/values based on a mapping. Mapping can be supplied as a single dictionary argument or as kwargs.
-
hset
(name, key, value)[source]¶ Set key to value within hash name.
Returns 1 if HSET created a new field, otherwise 0.
-
hmset
(name, mapping)[source]¶ Set key to value within hash
name
for each corresponding key and value from themapping
dict.
-
hsetnx
(name, key, value)[source]¶ Set key to value within hash name if key does not exist.
Returns 1 if HSETNX created a field, otherwise 0.
-
lrange
(name, start, end)[source]¶ Return a slice of the list
name
between positionstart
andend
.start
andend
can be negative numbers just like Python slicing notation.
-
finchan.env¶
runtime Environment
the env
object is a global singleton object,
other modules/extensions can access by just import it and can access/set attributes to env
.
Env¶
-
class
finchan.env.
Env
(*args, **kwargs)[source]¶ Global environment
-
dispatcher
¶ the dispatcher manager object
Return type: Dispatcher
-
ext_manager
¶ the extension manager object
Return type: ExtManager
-
finchan.dispatcher¶
Event Dispatcher
get events from event source and dispatch evnets to the subscriber.
Dispatcher¶
BackTrackDispatcher¶
-
class
finchan.dispatcher.
BackTrackDispatcher
(env)[source]¶ Dispatcher that dispatch backtrack events. the event sources generate events and put them into event queue, the main thread get events from event queue and dispatch them.
Parameters: env – global envirument -
now
¶ datetime of current logic time
-
LiveDispatcher¶
finchan.exts¶
Extension manager
-
class
finchan.exts.
ExtManager
(env, ext_paths='', **kwargs)[source]¶ Extension manager for finchan.
An finchan extension is an importable Python module that has a function with the signature:
def load_finchan_ext(env): # Do setup
This function is called after your extension is imported. *args and **kwargs is passed from configure file’s
config.live_track_exts
orconfig.backtrack_exts
‘s extension module name section depend on the run mode.You can also optionally define an
unload_finchan_ext()
function, which will be called if the user unloads the extension.You can put your extension modules anywhere you want, as long as they can be imported by Python’s standard import mechanism. However, to make it easy to write extensions, you can also put your extensions in a configured path
config.ext_paths
. This directory is added tosys.path
automatically.
finchan.exts.timer_source¶
Extend finchan¶
An finchan extension is an importable Python module that has a function with the signature:
def load_finchan_ext(*args, **kwargs):
# Do setup
This function is called after your extension is imported.
*args and **kwargs is passed from configure file’s config.live_track_exts
or
config.backtrack_exts
‘s extension module name section depend on the run mode.
You can also optionally define an unload_finchan_ext()
function, which will be called if the user unloads the extension.
You can put your extension modules anywhere you want, as long as
they can be imported by Python’s standard import mechanism. However,
to make it easy to write extensions, you can also put your extensions
in a configured path config.ext_path
.
This directory is added to sys.path
automatically.
the finchan
has two built-in extension module,
finchan.exts.timer_source
and finchan.exts.timer_callback
for test
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/qytz/finchan/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.
Write Documentation¶
finchan could always use more documentation, whether as part of the official finchan docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/qytz/finchan/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up finchan
for local development.
Fork the
finchan
repo on GitHub.Clone your fork locally:
$ git clone git@github.com:your_name_here/finchan.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv finchan $ cd finchan/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 finchan tests $ python setup.py test or py.test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check https://travis-ci.org/qytz/finchan/pull_requests and make sure that the tests pass for all supported Python versions.
AUTHORS¶
Finchan is written and maintained by qytz and various contributors:
Development Lead¶
- qytz <hhhhhf@foxmail.com>
Patches and Suggestions¶
None yet. Why not be the first?
History¶
0.2.0 (2018-11-15)¶
- optimized exit check mechanism, can exit quickly now.
- exts load interface has no parameters now.
- support multiple splited configure files.
- support extension groups.
0.1.3 (2018-10-27)¶
- remove global env object, you can reference by event.env.
- fix finchan.exts.timer_souce schedule format for month/year/week.
0.1.2 (2018-10-01)¶
- Fix pypi package.
- Support docker run.
- Add SYSTEM_EXITING event.
0.1.1 (2018-09-22)¶
- First release on PyPI.