Events API Classes

This part of the documentation covers the objects that represent data returned by the Events API.

The Event Object

class github3.events.Event(json, session: github3.session.GitHubSession)

Represents an event as returned by the API.

It structures and handles the data returned by via the Events section of the GitHub API.

Two events can be compared like so:

e1 == e2
e1 != e2

And that is equivalent to:

e1.id == e2.id
e1.id != e2.id
actor

A EventUser that represents the user whose action generated this event.

created_at

A datetime representing when this event was created.

id

The unique identifier for this event.

org

If present, a EventOrganization representing the organization on which this event occurred.

type

The type of event this is.

See also

Event Types Documentation

GitHub’s documentation of different event types

payload

The payload of the event which has all of the details relevant to this event.

repo

The string representation of the repository this event pertains to.

Changed in version 1.0.0: This restores the behaviour of the API. To get a tuple, representation, use self.repo.split('/', 1)

public

A boolean representing whether the event is publicly viewable or not.

as_dict()

Return the attributes for this object as a dictionary.

This is equivalent to calling:

json.loads(obj.as_json())
Returns

this object’s attributes serialized to a dictionary

Return type

dict

as_json()

Return the json data for this object.

This is equivalent to calling:

json.dumps(obj.as_dict())
Returns

this object’s attributes as a JSON string

Return type

str

classmethod from_dict(json_dict, session)

Return an instance of this class formed from json_dict.

classmethod from_json(json, session)

Return an instance of this class formed from json.

static list_types()

List available payload types.

new_session()

Generate a new session.

Returns

A brand new session

Return type

GitHubSession

property ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns

int

refresh(conditional: bool = False) github3.models.GitHubCore

Re-retrieve the information for this object.

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.repositories_by('kennethreitz')]

Without the return value, that would be an array of None’s and you would otherwise have to do:

repos = [r for i in g.repositories_by('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

Parameters

conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs

Returns

self

When accessing the payload of the event, you should notice that you receive a dictionary where the keys depend on the event type. Note:

  • where they reference an array in the documentation but index it like a dictionary, you are given a regular dictionary

  • where they reference a key as returning an object, you receive the equivalent object from the dictionary, e.g., for a Fork Event

    >>> event
    <Event [Fork]>
    >>> event.payload
    {u'forkee': <Repository [eweap/redactor-js]>}
    >>> event.payload['forkee']
    <ShortRepository [eweap/redactor-js]>
    

Using the dictionary returned as the payload makes far more sense than creating an object for the payload in this instance. For one, creating a class for each payload type would be insanity. I did it once, but it isn’t worth the effort. Having individual handlers as we have now which modify the payload to use our objects when available is more sensible.