Code

Inthing module

class inthing.Result(url)

Represents a successfully posted event.

The url attribute contains the URL to the the event’s page.

browse()

Open a webbrowser at this event.

class inthing.Stream(id=None, password=None, generator=None, silence_errors=False)

Inthing Stream class interface.

This class is the main interface for posting to an Inthing Stream. It represents a single Stream, and has methods to post the various event types.

Construct a new Stream object.

Parameters:
  • id (str) – The ID of your stream. This may be either a UUID (mixture of letters an numbers), or the URL of the stream.
  • password (str) – The stream’s password, if required. It’s possible for a stream to have no password, which allows for anyone to post to it.
  • generator (str) – A short string to identify what is creating events.
  • silence_errors (bool) – If True, ignore errors when posting events.
Return type:

Stream

add_event(event)

Add an event.

Parameters:event (Event) – Event you want to add.
browse()

Open this stream in your browser.

capture(title=u'Captured output', description=None, browse=False, stdout=True, stderr=False)

Capture stdout and stderr.

Parameters:
  • title (str) – Title of the captured event
  • description (str) – Optional description
  • browse (bool) – Open a webbrowse to new event?
  • stdout (bool) – Capture stdout?
  • stderr (bool) – Capture stderr?

This method returns a context manager, which will capture print output, and post it to a stream. Here is an example:

from inthing import Stream
stream = Stream.new()
with stream.capture(title="Capture Example") as capture:
    print('This output will go to a stream!')
capture.browse()
code(code, language=None, description=None, title=u'Code', markup=u'markdown', priority=0)

Add a (source) code event.

with open('example.py') as code_file:
    stream.code(code_file, language="Python")
Parameters:
  • code (str or open object) – Path to a file containing code, or an open file object
  • language (str) – Programming language.
  • description (str) – A description of the source dode.
  • title (str) – Title of the Event.
  • markup (str) – Markup type for the description.
Return type:

Result

image(path, description=None, title=u'New Photo', markup=u'markdown', priority=0)

Add an image event.

Parameters:
  • path (str) – A path to a JPG or PNG.
  • description (str) – Description of the image.
  • title (str) – Title of the image event.
  • markup (str) – Markup used to render description.
Return type:

Result

classmethod new()

Create a new unclaimed stream.

An unclaimed stream functions like any other stream, but is not owned by any user, and has no password set. Anyone may post events to an unclaimed stream, but in practice they are private as long as you don’t give away the ID or URL.

Rtype Stream:
>>> my_stream = Stream.new()
>>> my_stream.text('I just create a new stream!')
>>> print(my_stream.url)
screenshot(delay=0, description=None, title=u'New Screenshot', markup=u'markdown', priority=0)

Take a screenshot and post an event.

Parameters:
  • delay (int) – Number of seconds to wait before taking the screenshot.
  • description (str) – Description of the screenshot.
  • title (str) – Title of the event.
  • markup (str) – Markup of the description.
Return type:

Result

text(text, title=u'Text', markup=u'markdown', priority=0)

Add a text event to this stream.

>>> my_stream = Stream.new()
>>> result = my_stream.text('Hello, World!')
>>> result.browse()
Parameters:
  • text (str) – The text you want to associate with this event.
  • title (str) – The title of the event
Return type:

Result

class inthing.Event(title=u'New Event', type=u'text', priority=0, markup=u'markdown', description=None, text=None, generator=None, code_language=None)

Contains the details of a new event.

This class provides a more finely grained way of creating events. To use,
construct an Event instance and add it to a stream with inthing.Stream.add_event().

Store details for a single event.

This class is used in the low level interface for creating events. You probably want to used the methods on inthing.Stream for a simpler interface.

Here’s an example of using this class:

event = Event(title="Example text event", text="Hello, World!")
stream.add_event(event)
Parameters:
  • title (str) – The title of the event, shown as a header.
  • type (str) – The type of the event.
  • markup (str) – The markup used to render the descriptions, may be ‘text’, ‘html’, ‘markdown’
  • text (str) – Text associated with the event.
  • generator (str) – Text regarding what generated the event.
  • code_language (str) – The language used to syntax highlight code events.
add_image(path)

Add an image to the event.

Parameters:path (str) – Path to an image file
exception inthing.errors.BadResponse

The server returned an unexpected response.

exception inthing.errors.ConnectivityError

There was an issue reaching the server.

exception inthing.errors.EventError

An error relating to an attempt to post an event.

exception inthing.errors.EventFail(result)

The event contained invalid information.

print_error()

Print error details to stderr.

exception inthing.errors.RateLimited

Events are being posted to fast.

exception inthing.errors.StreamError

Base class for inthing Stream related errors.