For a nicely documented and clean Matrix client implementation in Python, see weechat-matrix[1] and the matrix-nio[2] library it's based on. There's also Mirage[3] which is also based on matrix-nio and is a GUI client.
Last I tried to read the spec (months? a couple of years? who can even remember these days), it kind of sucked. The allegedly separate server spec silently presumed knowledge of all of the client spec without any specific references, and the description of the merge strategy was organized as a sequence of forward(!) diffs of successive algorithm versions. I gave up.
The spec is ok, but you do have to bounce around a lot. There are still areas that need improvement for sure, but we’ve been using it for about a year now with some level of success in building a chat product.
[1]: https://spec.matrix.org/unstable/
[2]: https://matrix.org/clients/