项目作者: non-Jedi

项目描述 :
Python WSGI framework for developing matrix.org application-services
高级语言: Python
项目地址: git://github.com/non-Jedi/gyr.git
创建时间: 2017-03-17T19:10:35Z
项目社区:https://github.com/non-Jedi/gyr

开源协议:GNU General Public License v3.0

下载


Gyr

Come talk with us about Gyr on matrix at
#gyr:matrix.org!

Gyr is a framework for quickly developing matrix
application
services
in
python3. It provides a WSGI application and several other utilities for working
with matrix.

Gyr is designed to be a fairly thin layer of abstraction over application
service api—just enough to make things easy without pushing you so far from the
spec that you get confused.

Status

Gyr hasn’t been worked on in months. For a python application-service framework
under more active development I recommend checking out Cadair’s
python-appservice-framework.
Use at your own risk currently, and be especially aware of bugs like this one
caused by Gyr’s lack of
asynchronicity
. I hope to return to
this framework once I land async in
matrix-python-sdk
.

Very alpha! Most of the main functionality I’d envisioned is present, however
there’s poor to non-existent documentation and no unit tests. Contributions are
welcome.

Installation

Please install gyr with pip (in a virtualenv if you prefer):

  1. pip install gyr

Usage

I’ll try to show a bunch of functionality here, but see examples directory for
further usage examples.

  1. from gyr import server, matrix_objects
  2. application = server.Application("http://localhost:8008", "foobar")
  3. as_user = matrix_objects.MatrixUser("@example_as:example.com", application.Api)
  4. room = as_user.create_room(alias="#foo:example.com", is_public=True)
  5. def rm_hndlr(room_id):
  6. # Gyr will create a user for you if this returns true!
  7. return False
  8. def user_hndlr(user_id):
  9. # Gyr will create the room for you if this returns true!
  10. return False
  11. def txn_hndlr(events):
  12. for event in events:
  13. room.send_notice(
  14. "Received event type {} in room {} from user {}".format(event.type,
  15. event.room,
  16. event.user)
  17. )
  18. return True
  19. application.add_handlers(room_handler=rm_hndlr, transaction_handler=txn_hndlr,
  20. user_handler=user_hndlr)

Save as example.py. Then from the commandline:

  1. gunicorn example:application

Projects Using Gyr

Modules

gyr.server

server provides the WSGI application class. An instance of
gyr.server.Application functions as the WSGI app and will automatically
parse the request and call any handlers provided to the Application
instance.

gyr.api

api provides a helpful wrapper for
matrix-python-sdk‘s
api, changing the parts of the api that are different for application
services until such time as similiar changes are merged upstream. Pull
requests for these changes have been submitted, and some changes already
merged into master.

For working with the api, I recommend using the wrappers built around
specific objects which are available in gyr.matrix_objects.

gyr.matrix_objects

matrix_objects provides helpful wrapper classes around matrix users,
events and rooms. It is not designed to be easily used for the normal
client-server api but should provide most necessary functionality for
the manipulation of users and rooms that an application service might
need to do.

Pull requests enriching the functionality of these classes are very
welcome.