Giter VIP home page Giter VIP logo

synapse-admin-api-python's Introduction

Synapse-admin-api-python

Pypi License MIT Python Synapse Tests

A Python wrapper for Matrix Synapse admin API.

Versioning

This library now supports up to Synapse 1.60.0, any Admin API introduced after 1.60.0 may not be included in this version. However, newer changes to Admin API are planned to be included in this library. For planned update, see TODO.md. In the future, the version numbering convention will follow the version this library up to, for example, if this library supports up to 1.60.0, then the version number of this library will be 1.60.0. And the minor number will be reserved for bug fixes in this repo.

Releases older than 0.1.5 only work with HTTP/2

Get Started

Install from PyPi

pip install matrix-synapse-admin

Provide the connection information and access token in the first time of execution. You can either enter the information interactively or as arguments:

Interactively

>>> from synapse_admin import User
>>> user = User()
# The config creator is smart enough to determine the protocol and port by providing either one.
Enter the homeserver URL with port(e.g. https://example.com:443): https://example.com # Only need to be entered in the first time
Enter the access token (leave blank to get the access token by logging in): <access token or leave blank> # Only need to be entered in the first time
# If access token is left blank
Enter a username: admin
Enter a password:
Token retrieved successfully
Save to a config file? (Y/n)
>>> details_of_users = user.lists()
>>> print(details_of_users)
[{'name': '@admin:example.com', 'user_type': None, 'is_guest': 0, 'admin': 1, 'deactivated': 0, 'shadow_banned': False, 'displayname': 'Admin', 'avatar_url': 'mxc://example.com/ABCDEFG'}]
>>> print(details_of_users.total)
1

As arguments

>>> from synapse_admin import User
>>> user = User("example.com", 443, "<access token>", "https://")
>>> details_of_users = user.lists()
>>> print(details_of_users)
[{'name': '@admin:example.com', 'user_type': None, 'is_guest': 0, 'admin': 1, 'deactivated': 0, 'shadow_banned': False, 'displayname': 'Admin', 'avatar_url': 'mxc://example.com/ABCDEFG'}]
>>> print(details_of_users.total)
1

Unit Testing

Simply run the testing script

chmod +x testing_env.sh
./testing_env.sh

Documentation

Docstrings are present now in most methods and classes. If you see /equivalent to ".*"/, it's mean that you may want to refer back to the Synapse Admin API documentation.

More documentation are coming...

Additional features

In addition to the wrapper that wraps the official admin APIs, this wrapper also provides serval unofficial helper methods or admin APIs, they include:

  • Reactivate an deactivated account (User.reactivate)
  • Create a room (Room.create)
  • Send an announcement to everyone (Management.announce_all)
  • Delete media by id or by condition (Media.delete_media)

Contribution

If you want to help me to improve the quality of this project, you can submit an issue.

If you want to collaborate with us, feel free to Fork this project and open a pull request.

What can you do?

  • For Issue

    • Report any Error.
    • Request new features based on the Synapse Admin API
    • Ask questions if you do not understand something.
    • More.
  • For Pull request

    • Add comments to source code.
    • Add new features based on the Synapse Admin API
    • Correct any Error.
    • More.

synapse-admin-api-python's People

Contributors

emonical avatar knugihk avatar thebalaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

synapse-admin-api-python's Issues

"Iterable bodies must always iterate in bytestrings"

I just started testing your wrapper.

So far I can connect to our matrix server, get information (e.g. version, user list).
As soon as I try to send a body to the server (i.e. to create a user, send an announcement, ...), I get an error:

"Iterable bodies must always iterate in bytestrings"

Maybe I am just doing something wrong - is there any documentation or could you provide an example of user creation?

Thanks and best regards
Thomas

FYI: https://github.com/JOJ0/synadm

.. just had a look at current status of synapse admin tools (~medium impressive xD) and found a few, amongst which I like yours and https://github.com/JOJ0/synadm which already seems to have quite the endpoint coverage (haven't tried either yet). So this issue is just to let you know synadm is out there, maybe there's some synergy potential ๐Ÿค 

synapse >=1.92 does not return a python_version

using Management.version(), it should return a server_version and python_version.
But since synapse 1.94.0 it does not return a python_version in the JSON.

So your code produces an error.

I would also remove the python_version from the code. This may be backwards incompatible. You could also remove the python str from SynapseVersion (even more incompatible then ๐Ÿ˜† ).

Best way would be to check if the server_version is < 1.94.0, and if yes, include python_version. if higher, skip it.

Running tests

When i was trying to run the tests to find if there were any flaky tests in the project I got the error saying that "no such file or directory: 'synapse_test/admin.token'". Just wondering where this file locates.

User class not working

Hello,

I tried the example in your doc to get information of all users, but it didn't work. The errors are as follows:

Traceback (most recent call last):
File "/home/admin/trial2.py", line 62, in
client.lists()
File "/home/admin/.local/lib/python3.9/site-packages/synapse_admin/user.py", line 117, in lists
resp = self.connection.request(
File "/home/admin/.local/lib/python3.9/site-packages/synapse_admin/base.py", line 626, in request
return request(url, **kwargs)
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 1045, in get
return self.request(
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 821, in request
return self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 908, in send
response = self._send_handling_auth(
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 936, in _send_handling_auth
response = self._send_handling_redirects(
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 973, in _send_handling_redirects
response = self._send_single_request(request)
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 1009, in _send_single_request
response = transport.handle_request(request)
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 218, in handle_request
resp = self._pool.handle_request(req)
File "/usr/lib/python3.9/contextlib.py", line 135, in exit
self.gen.throw(type, value, traceback)
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: [Errno -2] Name or service not known

Avoid the anti flood

Hey, I've used your code and it worked very well, nice job !
In my opinion it would be useful to insert a command that avoids running into the antiflood of synapse
For example:
I wrote a script with which I generated about 60 rooms starting from a txt file that contained their names.
The server after the fifth / sixth room started giving some errors
To solve this, I inserted a 60-second sleep between the creation of one room and the next one

In my opinion it would be useful if this library will be able to disable the antiflood with a python command, or at least make it more flexible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.