Skip to main content

A Python package for HipChat’s v2 JSON REST API. It’s based on v2’s navigability and self-declaration.

Installation

HypChat can either be installed from PyPI:

pip install hypchat

Or from source:

python setup.py install

Concepts

There are two basic types in HypChat: Linker and RestObject. They are not meant to be instantiated directly but instead created as references from other objects.

Linker

A simple callable that represents an unfollowed reference.

l.url

The URL this object points to

l()

Calling a Linker will perform the request and return a RestObject

RestObject

A subclass of dict, contains additional functionality for links and actions.

Other Actions

Many of the v2 types define additional types, eg Rooms have methods for messaging, setting the topic, getting the history, and inviting users to the room. These are implemented as methods of subclasses. The complete listing is in the Type List.

Timezone Handling

HypChat uses aware datetime objects throughout by the dateutil module. However, the HipChat API universally uses UTC.

For methods that take a datetime, if a naive object is given, it will be assumed to be in UTC. If this is not what you mean, dateutil.tz has a wonderful selection of timezones available.

Usage

First, create a HypChat object with the token

hc = HypChat("mytoken")

If you use Hipchat Server

hc = HypChat("mytoken", endpoint="https://hipchat.example.com")

There are several root links:

rooms = hc.rooms()
users = hc.users()
emots = hc.emoticons()
caps = hc.capabilities()

In addition, the HypChat object has methods for creating objects and directly referencing the basic types.

For example, you might do:

for room in (r for r in hipchat.rooms(expand='items') if r['last_active'] < datetime.datetime(2013, 12, 1)):
        room.owner.message("Your room is dead; maybe archive it")

Since room.owner is a User stub, not just a generic object. (The Room objects are not stubs, since the expand keyword is used).

Downloading history is as easy as:

list(HypChat(token).get_room(id).history(datetime.datetime.utcnow()).contents())

Note that this may eat up many requests for large rooms.

Navigation

Any time an object is referenced in a value (eg room['owner']), a stub of that object is created, and the full object may be found with .self(). Stubs contain the ID of the object, the name (if applicable), and any links that object has-including self. This can be avoided by using the expand keyword.

Collections-such as rooms, users, and emots above-all have an 'items' key containing their list of things. In addition, the .contents() method will generate all of the items, handling pagination. As usual, object

Console

If you call python -m hypchat, a interactive prompt (using IPython if available) will appear. The environment will contain hipchat, an instance of the HypChat object. The token is pulled from ~/.hypchat, /etc/hypchat, or the environment variable HIPCHAT_TOKEN.

Type List

See TYPES.rst

TODO List

  • API Links

Download files

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

Source Distribution

hypchat-0.21.tar.gz (16.2 kB view details)

Uploaded Source

File details

Details for the file hypchat-0.21.tar.gz.

File metadata

  • Download URL: hypchat-0.21.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for hypchat-0.21.tar.gz
Algorithm Hash digest
SHA256 ef37a9cd8103bb13ad772b28ba9223ca9d4278371e374450c3ea2918df70a8e9
MD5 05df8c682be669f008a43bc79c94e820
BLAKE2b-256 b656e0a36bf88faf44eac567a0c785435c8ba73845e5259092bc51942543daf9

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