Welcome to pluralsight client for Python’s documentation!

pluralsight

https://img.shields.io/pypi/v/pluralsight.svg https://img.shields.io/travis/tonybaloney/pluralsight.svg Documentation Status

Pluralsight client library for API management

Features

  • Invitation management using the license API

  • User management using the license API

  • Team information

  • Invite URL generation

Usage

from pluralsight.licensing import LicensingAPIClient

client = LicensingAPIClient(plan, api_key)

invites = client.invites.get_all_invites()

Contents:

Installation

At the command line:

$ easy_install pluralsight

Or, if you have virtualenvwrapper installed:

$ mkvirtualenv pluralsight
$ pip install pluralsight

Usage

Licensing

To use pluralsight in a project

 1from pluralsight.licensing import LicensingAPIClient
 2
 3client = LicensingAPIClient(plan, api_key)
 4
 5# invites
 6invites = client.invites.get_all_invites()
 7
 8# users
 9users = client.users.get_all_users()
10
11# teams
12teams = client.teams.get_all_teams()

Invites

 1# This script will find an invitation for a user and show you the invite link
 2
 3from pluralsight.licensing import LicensingAPIClient
 4import sys
 5
 6invite_email = sys.argv[1]
 7plan = sys.argv[2]
 8api_key = sys.argv[3]
 9
10client = LicensingAPIClient(plan, api_key)
11
12invites = client.invites.get_invites(email=invite_email)
13
14print("Found {0} invites".format(len(invites)))
15
16for invite in invites:
17    print("Link - " + invite.generate_url(plan))
 1# This script will get all the outstanding invitations and send them an email
 2# via your Exchange Web Access API.
 3# pip install exchangelib
 4# Tested on Python 3.5
 5
 6from pluralsight.licensing import LicensingAPIClient
 7
 8from exchangelib import DELEGATE, Account, Credentials, Message, Mailbox
 9from exchangelib.folders import HTMLBody
10
11plan = 'your-plan-name'
12api_key = 'your-license-api-key'
13email = 'youremail.com'
14me = "Your name <{0}>".format(email)
15
16EXCHANGE_PASSWORD = 'password 123'
17
18# Username in WINDOMAIN\username format. Office365 wants usernames in PrimarySMTPAddress
19# ('myusername@example.com') format. UPN format is also supported.
20#
21# By default, fault-tolerant error handling is used. This means that calls may block for a long time
22# if the server is unavailable. If you need immediate failures, add 'is_service_account=False' to
23# Credentials.
24credentials = Credentials(username=email, password=EXCHANGE_PASSWORD)
25
26account = Account(primary_smtp_address=email, credentials=credentials,
27                  autodiscover=True)
28
29def generate_email(invite):
30    # Create message container - the correct MIME type is multipart/alternative.
31    subject = "Please register for your DevOps, Developer and Automation training portal access"
32
33    # Customize this to your own message. 
34    html = """\
35    <html>
36      <body>
37        <p>Hi,<br><br>
38           Happy New Year. You should have received emails from me regarding access to pluralsight.com, invitations are limited
39           to a small group of individuals, of which you are one. Invitations will expire/be reallocated for any users that
40           have not accepted their invitations by the deadline. <br><br>
41           This is your unique registration link - <a href="{0}">{0}</a>.
42           <br><br>
43           Please register this week, <u>do not forward this email</u>. Registration links are unique.<br><br>
44           Regards,<br>
45           
46        </p>
47      </body>
48    </html>
49    """.format(invite.generate_url(plan))
50
51    return Message(
52        account=account,
53        folder=account.sent,
54        subject=subject,
55        body=HTMLBody(html),
56        to_recipients=[Mailbox(email_address=invite.email)]
57    )
58
59client = LicensingAPIClient(plan, api_key)
60
61invites = client.invites.get_all_invites()
62
63print("Fetched {0} invites".format(len(invites)))
64
65for invite in invites:
66    msg = generate_email(invite)
67
68    try:
69        msg.send_and_save()
70        print("Sent invite reminder to {0}".format(invite.email))
71    except error:
72        print(error)
73        print("Failed to send invite reminder to {0}".format(invite.email))

pluralsight.licensing package

Submodules

pluralsight.licensing.client module

class pluralsight.licensing.client.LicensingAPIClient(plan, api_key)[source]

Bases: object

The licensing API client

delete(uri)[source]
get(uri, params=None)[source]
post(uri, data=None)[source]
put(uri, data=None)[source]

pluralsight.licensing.invites module

class pluralsight.licensing.invites.InvitesClient(client)[source]

Bases: object

Invites API

cancel_invite(id)[source]

Cancel an invitation

Parameters

id (str) – The identifier

Return type

None

get_all_invites()[source]

Get all invites

Returns

A list of Invite

Return type

list of Invite

get_invite(id)[source]

Fetch an invitation by ID

Parameters

id (str) – The identifier

Returns

An instance Invite

Return type

Invite

get_invites(email=None, note=None, team_id=None)[source]

Get invitations matching certain filters

Parameters
  • email (str) – The users’ email address

  • team_id (str) – The team identifier

  • note (str) – Additional notes on the user

Returns

A list of Invite

Return type

list of Invite

invite_user(email, team_id=None, note=None)[source]

Create a new invitation

Parameters
  • email (str) – The users’ email address

  • team_id (str) – The team identifier

  • note (str) – Additional notes on the user

Returns

An instance Invite

Return type

Invite

update_invite(id, note)[source]

Update an invitation

Parameters
  • id (str) – The identifier

  • note (str) – Additional notes on the user

pluralsight.licensing.teams module

class pluralsight.licensing.teams.TeamsClient(client)[source]

Bases: object

Teams API

get_all_teams(name=None)[source]

Get all teams

Parameters

name (str) – Filter by name

Returns

A list of Team

Return type

list of Team

get_team(id)[source]

Fetch a team by ID

Parameters

id (str) – The identifier

Returns

An instance Team

Return type

Team

pluralsight.licensing.users module

class pluralsight.licensing.users.UsersClient(client)[source]

Bases: object

Users API

delete_user(id)[source]

Delete an existing user

Parameters

id (str) – The identifier

Return type

None

get_all_users(first_name=None, last_name=None, email=None, note=None, team_id=None)[source]

Get all users

Parameters
  • first_name (str) – Filter by first name

  • last_name (str) – Filter by last name

  • email (str) – Filter by email

  • note (str) – Filter by note

  • team_id (str) – Filter by team ID

Returns

A list of User

Return type

list of User

get_user(id)[source]

Fetch a user by ID

Parameters

id (str) – The identifier

Returns

An instance User

Return type

User

update_user(id, team_id, note)[source]

Update a user

Parameters
  • id (str) – The identifier

  • team_id (str) – Team the user belongs to

  • note (str) – Additional notes on the user

Module contents

pluralsight.reports package

Submodules

pluralsight.reports.client module

class pluralsight.reports.client.ReportsAPIClient(plan, api_key)[source]

Bases: object

Reports API client

download_course_completion_report(plan, path, start_date=None, end_date=None)[source]

Download the course completion report and store in a file

Parameters
  • plan (str) – The plan name

  • path (str) – Path to the downloaded CSV

  • start_date (str) – (optional) Start date in format YYYY-MM-DD

  • end_date (str) – (optional) End date in format YYYY-MM-DD

Returns

The filename

download_course_usage_report(plan, path, start_date=None, end_date=None)[source]

Download the course usage report and store in a file

Parameters
  • plan (str) – The plan name

  • path (str) – Path to the downloaded CSV

  • start_date (str) – (optional) Start date in format YYYY-MM-DD

  • end_date (str) – (optional) End date in format YYYY-MM-DD

Returns

The filename

download_user_report(plan, path)[source]

Download the user report and store in a file

Parameters
  • plan (str) – The plan name

  • path (str) – Path to the downloaded CSV

Returns

The filename

Module contents

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/tonybaloney/pluralsight/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.

  • Any details about your local setup that might be helpful in troubleshooting.

  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.

Write Documentation

pluralsight could always use more documentation, whether as part of the official pluralsight docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/tonybaloney/pluralsight/issues.

If you are proposing a feature:

  • Explain in detail how it would work.

  • Keep the scope as narrow as possible, to make it easier to implement.

  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up pluralsight for local development.

  1. Fork the pluralsight repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/pluralsight.git
    
  3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:

    $ mkvirtualenv pluralsight
    $ cd pluralsight/
    $ python setup.py develop
    
  4. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:

    $ flake8 pluralsight tests
    $ python setup.py test
    $ tox
    

    To get flake8 and tox, just pip install them into your virtualenv.

  6. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  7. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.

  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.

  3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check https://travis-ci.org/tonybaloney/pluralsight/pull_requests and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ python -m unittest tests.test_pluralsight

Credits

Development Lead

Contributors

None yet. Why not be the first?

History

1.2.1 (12th July 2018)

  • Decode report download to remove BOM from Python 3

1.2.0 (5th Feb 2018)

  • Fixed issue with report downloads just being named the plan instead of a CSV name

0.16.0 (20th Jan 2017)

  • Added string representations for the core models

0.15.0 (19th Jan 2017)

  • Add support for filtering invitations

0.14.0 (17th Jan 2017)

  • Add support for generating the invite URL from an invite object using Invite.`generate_url()`

0.13.0 (21st Dec 2016)

  • Add support for cancelling invitations

0.12.0 (20th Dec 2016)

  • Fix bug in initialization of invite objects

0.11.0 (20th Dec 2016)

  • Provide the error message from the Pluralsight API on non-20x responses

0.10.0 (2016-12-12)

  • First stable release on PyPI.

  • Support for models, invites, users and reports

Indices and tables