Skip to main content
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.

Goals

  • 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.

Installation

pip install pydiscourse

Examples

Create a client connection to a Discourse server:

from pydiscourse import DiscourseClient
client = DiscourseClient(
        'http://example.com',
        api_username='username',
        api_key='areallylongstringfromdiscourse')

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', 'knight@python.org', 'justafleshwound')

Implement SSO for Discourse with your Python server:

@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)

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

1.7.0

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

  • Add support for Python 3.12

1.6.1

  • Adds posts_by_number endpoint from @Dettorer

1.6.0

  • 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

1.5.0

  • 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

1.4.0

  • Documented here as skipped release

1.3.0

  • Add fix for handling global Discourse timeouts

  • Add group owners

  • Update API for add_group_owner

1.2.0

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

  • Added numerous new endpoint queries

  • Updated category querying

1.1.2

  • Fix for Discourse users API change

1.1.1

  • Fix for empty dictionary and 413 API response

  • Fix for getting member groups

1.1.0

  • Added ability to follow redirects in requests

1.0.0

  • Authenticate with headers

0.9.0

  • Added rate limiting support

  • Added some support for user activation

0.8.0

  • 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

0.7.0

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

0.6.0

  • Adds method to add user to group by user ID

0.5.0

  • Adds badges functionality

0.4.0

  • Adds initial groups functionality

0.3.2

  • SSO functionality fixes

0.3.1

  • Fix how empty responses are handled

0.3.0

  • Added method to unsuspend suspended user

0.2.0

  • Inital fork, including gberaudo’s changes

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

  • Packaging on PyPI

0.1.0.dev

All pre-PyPI development

Metadata

Release files for pydiscourse 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydiscourse 1.7.0
File Size Uploaded
pydiscourse-1.7.0.tar.gz 19.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydiscourse 1.7.0
File Interpreter ABI Platform
pydiscourse-1.7.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 35.9 kB

Release files / pydiscourse-1.7.0.tar.gz

Download URL pydiscourse-1.7.0.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e090b9143750941aef5042bd8a9cdb93376abf6c18fe5ebbf15d7813acbdafb3
BLAKE2b-256 checksum
How to use checksums
a35b559d8c91cdb4bff9095916d1ac885fc265bef42e15815b7b430cb6e1384e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / pydiscourse-1.7.0-py2.py3-none-any.whl

Download URL pydiscourse-1.7.0-py2.py3-none-any.whl
Size 16.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d3ddf02510fb22dc425dfb7d81e6c363a14503ec53a7f7cb0d16d3f1f13259c4
BLAKE2b-256 checksum
How to use checksums
a88e3ff52fa942d036f9c8a5043b0f24d9be60970dfce2947c39b3d3012035b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

1.7.0 This release

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

1 release file

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page