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.

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

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.1.1.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydiscourse-1.1.1-py2.py3-none-any.whl (14.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pydiscourse-1.1.1.tar.gz.

File metadata

  • Download URL: pydiscourse-1.1.1.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for pydiscourse-1.1.1.tar.gz
Algorithm Hash digest
SHA256 06172960445f03e7e36c1e94730e89cbe9b8ea8099545776379506fb6fd88eac
MD5 dbf585e2bc02a80fac0c6d181676b97f
BLAKE2b-256 836e6933e2b9ac7922fd0b64a9d9e26087d397f71cc49d6d21e3c1864a9c9c28

See more details on using hashes here.

File details

Details for the file pydiscourse-1.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: pydiscourse-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for pydiscourse-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e396cc055243d8520492ae186b580afe00d3335a24f976a488959c3ab393330d
MD5 cee4e47ff307f94ade29d1acec3f9254
BLAKE2b-256 6688b69a3cc61521c199d8b515a36fb7682b7e6e28ddb3c59c3f1859fbff8b4f

See more details on using hashes here.

Supported by

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