Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.4 KiB
ReStructuredText
Raw Permalink Normal View History

2016-04-07 16:48:01 -04:00
===========
2014-04-04 13:25:42 -07:00
pydiscourse
2016-04-07 16:48:01 -04:00
===========
2025-02-25 10:50:49 +01:00
.. image:: https://img.shields.io/pypi/v/pydiscourse?color=blue
:alt: PyPI
:target: https://pypi.org/project/pydiscourse/
.. image:: https://github.com/pydiscourse/pydiscourse/workflows/Tests/badge.svg
2016-04-07 17:50:27 -04:00
:alt: Build Status
:target: https://github.com/pydiscourse/pydiscourse/actions
2016-04-07 17:50:27 -04:00
2019-10-05 21:05:50 -04:00
.. image:: https://img.shields.io/badge/Check%20out%20the-Docs-blue.svg
:alt: Check out the Docs
:target: https://discourse.readthedocs.io/en/latest/
2014-06-13 15:37:42 +00:00
A Python library for working with Discourse.
2016-04-07 17:41:54 -04:00
This is a fork of the original Tindie version. It was forked to include fixes,
additional functionality, and to distribute a package on PyPI.
Goals
=====
2016-04-08 18:27:02 -04:00
* Exceptional documentation
* Support all supported Python versions
2016-04-07 17:41:54 -04:00
* Provide functional parity with the Discourse API, for the currently supported
version of Discourse (something of a moving target)
2016-04-08 18:27:02 -04:00
The order here is important. The Discourse API is itself poorly documented so
the level of documentation in the Python client is critical.
Installation
============
::
pip install pydiscourse
2014-04-04 13:25:42 -07:00
2014-04-04 23:09:23 -07:00
Examples
2016-04-07 16:48:01 -04:00
========
2025-02-25 10:34:18 +01:00
Create a client connection to a Discourse server:
2014-04-04 14:27:33 -07:00
2025-02-25 10:34:18 +01:00
.. code:: python
2014-04-04 14:27:33 -07:00
2025-02-25 10:34:18 +01:00
from pydiscourse import DiscourseClient
client = DiscourseClient(
'http://example.com',
api_username='username',
api_key='areallylongstringfromdiscourse')
2014-04-04 23:09:23 -07:00
2025-02-25 10:34:18 +01:00
Get info about a user:
2014-04-04 14:27:33 -07:00
2025-02-25 10:34:18 +01:00
.. code:: python
2014-04-04 14:27:33 -07:00
2025-02-25 10:34:18 +01:00
user = client.user('eviltrout')
print user
2014-04-04 14:27:33 -07:00
2025-02-25 10:34:18 +01:00
user_topics = client.topics_by('johnsmith')
print user_topics
2014-04-04 14:27:33 -07:00
2025-02-25 10:34:18 +01:00
Create a new user:
2014-06-13 15:37:42 +00:00
2025-02-25 10:34:18 +01:00
.. code:: python
user = client.create_user('The Black Knight', 'blacknight', 'knight@python.org', 'justafleshwound')
Implement SSO for Discourse with your Python server:
.. code:: python
@login_required
def discourse_sso_view(request):
payload = request.GET.get('sso')
signature = request.GET.get('sig')
nonce = sso_validate(payload, signature, SECRET)
url = sso_redirect_url(nonce, SECRET, request.user.email, request.user.id, request.user.username)
return redirect('http://discuss.example.com' + url)
2014-06-13 15:37:42 +00:00
2014-04-04 23:09:23 -07:00
Command line
2016-04-07 16:48:01 -04:00
============
2014-04-04 14:27:33 -07:00
2025-02-25 10:34:18 +01:00
To help experiment with the Discourse API, pydiscourse provides a simple command line client:
.. code:: bash
2014-04-04 23:09:23 -07:00
2025-02-25 10:34:18 +01:00
export DISCOURSE_API_KEY=your_master_key
pydiscoursecli --host-http://yourhost --api-user-system latest_topics
pydiscoursecli --host-http://yourhost --api-user-system topics_by johnsmith
pydiscoursecli --host-http://yourhost --api-user-system user eviltrout