Skip to main content

"A Python library for the Discourse API"

Project description

Build Status Check out the Docs

A Python library for working with Discourse.

This is a fork of the original Tindie version. It was forked to include fixes, additional functionality, and to distribute a package on PyPI.


  • Exceptional documentation

  • Support all supported Python versions

  • Provide functional parity with the Discourse API, for the currently supported version of Discourse (something of a moving target)

The order here is important. The Discourse API is itself poorly documented so the level of documentation in the Python client is critical.


pip install pydiscourse


Create a client connection to a Discourse server:

from pydiscourse import DiscourseClient
client = DiscourseClient(

Get info about a user:

user = client.user('eviltrout')
print user

user_topics = client.topics_by('johnsmith')
print user_topics

Create a new user:

user = client.create_user('The Black Knight', 'blacknight', '', 'justafleshwound')

Implement SSO for Discourse with your Python server:

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.username)
    return redirect('' + url)

Command line

To help experiment with the Discourse API, pydiscourse provides a simple command line client:

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

Release history


  • Possible breaking change: Change search() term paramater from term to q, fixes search. Thanks @weber-s

  • Add support for Python 3.12


  • Adds posts_by_number endpoint from @Dettorer


  • Breaking: toggle_gravatar, pick_avatar, create_group now require keyword arguments where keyword arguments were used. This may break existing code if you have not referenced these by keyword!

  • Introduced ruff and black into pre-commit hook

  • Added lint job to GitHub Actions, tests will run if and only if lint job passes.

  • Sundry code cleanup


  • Owner creation endpoint update from @akhmerov

  • Python 3.11 support from @Dettorer

  • Group membership fixes from @inducer

  • Rate limiting fixes from @inducer

  • Latest posts endpoint from @max-lancaster


  • Documented here as skipped release


  • Add fix for handling global Discourse timeouts

  • Add group owners

  • Update API for add_group_owner


  • BREAKING? Dropped support for Python 2.7, 3.4, 3.5

  • Added numerous new endpoint queries

  • Updated category querying


  • Fix for Discourse users API change


  • Fix for empty dictionary and 413 API response

  • Fix for getting member groups


  • Added ability to follow redirects in requests


  • Authenticate with headers


  • Added rate limiting support

  • Added some support for user activation


  • Add some PR guidance

  • Add support for files in the core request methods

  • Adds numerous new API controls, including:
    • tag_group

    • user_actions

    • upload_image

    • block

    • trust_level_lock

    • create_site_customization (theme)

    • create_color_scheme

    • color_schemes

    • add_group_members

    • group_members

    • group_owners

    • delete_group

    • create_group

    • group

    • customize_site_texts

    • delete_category

    • user_emails

    • update_topic_status

    • create_post

    • update_topic

    • update_avatar

    • user_all


  • Place request parameters in the request body for POST and PUT requests. Allows larger request sizes and solves for URI Too Large error.


  • Adds method to add user to group by user ID


  • Adds badges functionality


  • Adds initial groups functionality


  • SSO functionality fixes


  • Fix how empty responses are handled


  • Added method to unsuspend suspended user


  • Inital fork, including gberaudo’s changes

  • Packaging cleanup, dropping Python 2.6 support and adding Python 3.5, PyPy, PyPy3

  • Packaging on PyPI

All pre-PyPI development

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydiscourse-1.7.0.tar.gz (19.7 kB view hashes)

Uploaded Source

Built Distribution

pydiscourse-1.7.0-py2.py3-none-any.whl (16.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page