gofigr package

Module contents

Copyright (c) 2022, Flagstaff Solutions, LLC All rights reserved.

class gofigr.ApiId(api_id)

Bases: tuple

api_id

Alias for field number 0

class gofigr.AssetSync(gf, workspace_id=None, asset_log=None)[source]

Bases: object

Provides drop-in replacements for open, read_xlsx, read_csv which version the data with the GoFigr service.

property analysis_id

Returns the analysis ID from the parent GoFigr instance.

clear_revisions()[source]

Clears the revision log

open(pathlike, *args, **kwargs)[source]

Syncs the data at pathlike with GoFigr and returns an open file handle. Drop-in replacement for open().

open_and_get_revision(pathlike, *args, **kwargs)[source]

Syncs the data at pathlike with GoFigr and returns a tuple of file handle, AssetRevision instance.

process_deferred_syncs()[source]

Runs sync_revision for each stashed path now that analysis is resolved, then clears the list.

property revisions

Returns all revisions in the log.

sync(pathlike, quiet=False)[source]
Syncs an asset: calculates the checksum for the file and either uploads it to GoFigr (if checksum isn’t found)

or returns the existing revision.

Parameters:
  • pathlike – path to the file

  • quiet – suppress Jupyter widget output

Returns:

pathlike

sync_revision(pathlike)[source]

Syncs an asset: calculates the checksum for the file and either uploads it to GoFigr (if checksum isn’t found) or returns the existing revision.

Parameters:

pathlike – path to the file

Returns:

AssetRevision instance

class gofigr.FindByName(name, description=None, create=False)[source]

Bases: object

Used as argument to configure() to specify that we want to find an analysis/workspace by name instead of using an API ID

class gofigr.GoFigr(username=None, password=None, api_key=None, url='https://api.gofigr.io', authenticate=True, workspace_id=None, anonymous=False, asset_log=None)[source]

Bases: object

The GoFigr client. Handles all communication with the API: authentication, figure creation and manipulation, sharing, retrieval of user information, etc.

property analysis_id

Returns the analysis API ID, or None if analysis is pending or unset.

property analysis_pending

Returns True if analysis is a NotebookName that hasn’t been resolved yet.

property api_url

Full URL to the API endpoint.

property app_url

Returns the URL to the GoFigr app

authenticate()[source]

Authenticates with the API.

Returns:

True

create_api_key(name, expiry=None, workspace=None)[source]

Creates an API key

Parameters:
  • name – name of the key to create

  • expiry – expiration date. If None, the key will not expire.

  • workspace – workspace for which the key is to be valid. If None, key will have access to the same workspaces as the user.

Returns:

ApiKey instance

find_analysis(workspace, query)[source]

Finds an analysis within a workspace

Parameters:
  • workspace – parent workspace (a gf.Workspace object)

  • query – gf.Analysis, UUID string, ApiId, or FindByName

Returns:

gf.Analysis object

find_figure(analysis, query)[source]

Finds a figure within an analysis

Parameters:
  • analysis – parent analysis (a gf.Analysis object)

  • query – gf.Figure, UUID string, ApiId, or FindByName

Returns:

gf.Figure object

find_workspace(query)[source]

Finds a workspace.

Parameters:

query – gf.Workspace, UUID string, ApiId, or FindByName

Returns:

gf.Workspace object

get_api_key(api_id)[source]

Gets information about a specific API key

heartbeat(throw_exception=True)[source]

Checks whether we can communicate with the API. Currently, this works by polling /api/v1/info.

Parameters:

throw_exception – throw an exception if response code is not 200

Returns:

Response

property jwt_url

Full URL to the JWT endpoint (for authentication).

list_api_keys()[source]

Lists all API keys

open(*args, **kwargs)[source]

Opens a file using the default DataSync object

property organizations

Returns a list of all organizations that the current user is a member of.

property primary_workspace

Returns the primary workspace for this user.

Returns:

Workspace instance

reserve_short_id_prefix()[source]

Reserve a short ID prefix from the server. The prefix can be combined with a sequential base62 index to generate compact, unique short IDs for figure revisions.

Returns:

8-character alphanumeric prefix string

revoke_api_key(api_id)[source]

Revokes an API key

server_info()[source]

Returns cached server info from the /info/ endpoint.

Returns:

dict with server info, or {} if the call fails (e.g. old server)

set_access_token(token)[source]

Set the access token for Bearer authentication (e.g. from Auth0 device flow).

property sync

Returns the default AssetSync object

update_user_info(user_info, username=None)[source]

Updates user information for a user.

Parameters:
  • user_info – UserInfo instance

  • username – optional username. This is for testing only – you will get an error if attempting to update information for anybody other than yourself.

Returns:

refreshed UserInfo from server

user_info(username=None)[source]

Retrieves information about a user.

Parameters:

username – username. Set to None for self.

Returns:

UserInfo object.

property workspaces

Returns a list of all workspaces that the current user is a member of.

class gofigr.NotebookName[source]

Bases: object

Used as argument to configure() to specify that we want the analysis name to default to the name of the notebook

class gofigr.UserInfo(username, first_name, last_name, email, date_joined, is_active, avatar, is_staff, user_profile)[source]

Bases: object

Stores basic information about a user: username, email, etc.

static from_json(obj)[source]

Parses a UserInfo object from JSON

Parameters:

obj – JSON representation

Returns:

UserInfo instance

to_json()[source]

Converts this UserInfo object to json

gofigr.assert_one(elements, error_none=None, error_many=None)[source]

Asserts that a list/tuple contains only a single element (raising an exception if not), and returns that element.

Parameters:
  • elements – list/tuple

  • error_none – error message if input is empty

  • error_many – error message if multiple elements are present

Returns:

the single element in the input

gofigr.find_config(current_dir=None, filename='.gofigr')[source]

Recursively searches for the GoFigr configuration file starting in current_dir, then walking up the directory hierarchy. If one is not found, we then check the user’s home directory.

Parameters:
  • current_dir – start directory. Defaults to current directory.

  • filename – filename to look for. Defaults to .gofigr.

Returns:

path if found, or None

gofigr.load_ipython_extension(ip)[source]

Loads the Jupyter extension. Present here so that we can do “%load_ext gofigr” without having to refer to a subpackage.

Parameters:

ip – IPython shell

Returns:

None

Submodules

gofigr.jupyter module

Copyright (c) 2022, Flagstaff Solutions, LLC All rights reserved.

class gofigr.jupyter.JupyterPublisher(*args, clear=True, **kwargs)[source]

Bases: Publisher

Adds Jupyter-specific functionality to GoFigr’s base Publisher class.

auto_publish_hook(extension, data, suppress_display=None)[source]

Hook for automatically publishing figures without an explicit call to publish().

Parameters:
  • extension – GoFigrExtension instance

  • data – data being published. This will usually be a dictionary of mime formats.

  • suppress_display – if used in an auto-publish hook, this will contain a callable which will suppress the display of this figure using the native IPython backend.

Returns:

None

publish(*args, **kwargs)[source]

Publishes a revision to the server.

Parameters:
  • fig – figure to publish. If None, we’ll use plt.gcf()

  • target – Target figure to publish this revision under. Can be a gf.Figure instance, an API ID, or a FindByName instance. Ignored when auto_assign=True.

  • dataframes – dictionary of dataframes to associate & publish with the figure

  • metadata – metadata (JSON) to attach to this revision

  • backend – backend to use, e.g. MatplotlibBackend. If None it will be inferred automatically based on figure type

  • image_options – backend-specific params passed to backend.figure_to_bytes

  • suppress_display – if used in an auto-publish hook, this will contain a callable which will suppress the display of this figure using the native IPython backend.

  • files – either (a) list of file paths or (b) dictionary of name to file path/file obj

  • annotators – list of annotators to use. Defaults to self.annotators

  • auto_assign – if True, the server will use AI to automatically assign the revision to the correct figure. The revision will have is_processing=True until assignment completes. Use revision.wait_for_processing() to wait for completion. If None, uses the publisher’s default (self.auto_assign).

Returns:

FigureRevision instance

gofigr.jupyter.configure(username=None, password=None, api_key=None, workspace=None, analysis=NotebookName, url='https://api.gofigr.io', default_metadata=None, auto_publish=True, watermark=None, annotators=(<class 'gofigr.annotators.NotebookMetadataAnnotator'>, <class 'gofigr.annotators.EnvironmentAnnotator'>, <class 'gofigr.annotators.CellIdAnnotator'>, <class 'gofigr.annotators.CellCodeAnnotator'>, <class 'gofigr.annotators.SystemAnnotator'>, <class 'gofigr.annotators.PipFreezeAnnotator'>, <class 'gofigr.annotators.BackendAnnotator'>, <class 'gofigr.annotators.HistoryAnnotator'>, <class 'gofigr.annotators.GitAnnotator'>, <class 'gofigr.annotators.ScriptAnnotator'>), notebook_name=None, notebook_path=None, backends=(<class 'gofigr.backends.plotnine.PlotnineBackend'>, <class 'gofigr.backends.matplotlib.MatplotlibBackend'>, <class 'gofigr.backends.plotly.PlotlyBackend'>, <class 'gofigr.backends.py3dmol.Py3DmolBackend'>), widget_class=<class 'gofigr.widget.DetailedWidget'>, save_pickle=True, show_watermark=True, auto_assign=False, _show_widget=True)[source]

Configures the Jupyter plugin for use.

Parameters:
  • username – GoFigr username (if used instead of API key)

  • password – GoFigr password (if used instead of API key)

  • api_key – API Key (if used instead of username and password)

  • url – API URL

  • workspace – one of: API ID (string), ApiId instance, or FindByName instance

  • analysis – one of: API ID (string), ApiId instance, FindByName, or NotebookName instance

  • default_metadata – dictionary of default metadata values to save for each revision

  • auto_publish – if True, all figures will be published automatically without needing to call publish()

  • watermark – custom watermark instance (e.g. DefaultWatermark with custom arguments)

  • annotators – list of annotators to use. Default: DEFAULT_ANNOTATORS

  • notebook_name – name of the notebook (if you don’t want it to be inferred automatically)

  • notebook_path – path to the notebook (if you don’t want it to be inferred automatically)

  • backends – backends to use (e.g. MatplotlibBackend, PlotlyBackend)

  • widget_class – Widget type to show, e.g. DetailedWidget or CompactWidget. It will appear below the published figure

  • save_pickle – if True, will save the figure in pickle format in addition to any of the image formats

  • show_watermark – True to show watermarked figures instead of original. False to always display the unmodified figure. Default True.

  • auto_assign – if True, the server will use AI to automatically assign revisions to the correct figure based on image content. Default False.

Returns:

None

gofigr.jupyter.download_all(api_id, path)[source]

Downloads all files attached to a revision

Parameters:
  • api_id – API ID of the revision containing the files

  • path – directory where to save the files

Returns:

number of bytes written

gofigr.jupyter.download_file(api_id, file_name, path)[source]

Downloads a file and saves it.

Parameters:
  • api_id – API ID of the revision containing the file

  • file_name – name of the file to download

  • path – where to save the file (either existing directory or full path with the file name)

Returns:

number of bytes written

gofigr.jupyter.get_extension()[source]

Returns the GoFigr Jupyter extension instance

gofigr.jupyter.get_gofigr()[source]

Gets the active GoFigr object.

gofigr.jupyter.load_pickled_figure(api_id)[source]

Unpickles a GoFigr revision and returns it as a backend-specific Python object, e.g. a plt.Figure if the figure was generated with matplotlib. Throws a RuntimeException if the figure is not found or does not have pickle data.

Parameters:

api_id – API ID of the revision

Returns:

backend-dependent figure object, e.g. plt.Figure().

gofigr.jupyter.parse_uuid(val)[source]

Attempts to parse a UUID, returning None if input is not a valid UUID.

Parameters:

val – value to parse

Returns:

UUID (as a string) or None

gofigr.jupyter.publish(fig=None, backend=None, **kwargs)[source]

Publishes a figure. See gofigr.jupyter.Publisher.publish() for a list of arguments. If figure and backend are both None, will publish default figures across all available backends.

Parameters:
  • fig – figure to publish

  • backend – backend to use

  • kwargs

Returns:

gofigr.jupyter.require_configured(func)[source]

Decorator which throws an exception if configure() has not been called yet.

Parameters:

func

Returns:

gofigr.models module

Copyright (c) 2022, Flagstaff Solutions, LLC All rights reserved.

class gofigr.models.Base64Field(name, parent=None, derived=False)[source]

Bases: Field

Timestamp field

clone()[source]

Creates a clone of this field.

Returns:

cloned field

to_internal_value(gf, data)[source]

Parses the value of this field from JSON primitives.

Parameters:
  • gf – GoFigr instance

  • data – parsed JSON primitives

Returns:

parsed value

to_representation(value)[source]

Converts the value of this field to a JSON-serializable primitive

class gofigr.models.CodeLanguage[source]

Bases: ABC

For code data objects, the programming language of the embedded code.

PYTHON = 'Python'
R = 'R'
class gofigr.models.DataField(name, entity_type, many=False, read_only=False, backlink_property=None, parent=None, derived=False, sort_key=None, nested=False)[source]

Bases: LinkedEntityField

Customizes a LinkedEntityField so that the entity data is fully embedded in the representation

clone()[source]

Creates a clone of this field.

Returns:

cloned field

to_representation(value)[source]

Converts the value of this field to a JSON-serializable primitive

class gofigr.models.DataType[source]

Bases: ABC

Enum for different types of data we can store inside a FigureRevision.

CODE = 'code'
DATA_FRAME = 'dataframe'
FILE = 'file'
IMAGE = 'image'
TEXT = 'text'
class gofigr.models.Field(name, parent=None, derived=False)[source]

Bases: object

Describes a dynamically created object field, i.e. figure name, revision etc.

clone()[source]

Creates a clone of this field.

Returns:

cloned field

to_internal_value(gf, data)[source]

Parses the value of this field from JSON primitives.

Parameters:
  • gf – GoFigr instance

  • data – parsed JSON primitives

Returns:

parsed value

to_representation(value)[source]

Converts the value of this field to a JSON-serializable primitive

class gofigr.models.FlexibleStorageInfo(vendor, params)[source]

Bases: NestedMixin

Stores information required for flexible storage

classmethod from_json(data)[source]

Parses this object from JSON

to_json()[source]

Converts this object to JSON

class gofigr.models.FlexibleStorageMixin[source]

Bases: object

Mixin for getting/setting custom storage parameters if allowed by subscription

get_storage_info()[source]

Gets the storage information for this workspace/organization.

Returns:

FlexibleStorateInfo instance

set_storage_info(vendor, params)[source]

Sets the storage information for this workspace/organization.

Parameters:
  • vendor – vendor name

  • params – vendor-specific storage parameters

Returns:

FlexibleStorageInfo instance returned from the server

test_storage(vendor, params)[source]

Runs a storage test for flexible storage parameters.

Parameters:
  • vendor – vendor name

  • params – vendor-specific storage parameters

Returns:

FlexibleStorageInfo instance returned from the server

class gofigr.models.InvitationMixin(api_id=None, parse=False, **kwargs)[source]

Bases: ModelMixin

Represents an invitation to join a workspace.

accept()[source]

Accepts this invitation

delete(**kwargs)[source]

Deletes an object on the server. This cannot be undone.

Parameters:

kwargs – specify delete=True to actually delete the object.

Returns:

fetch()[source]

Updates all fields from the server. Note that any unsaved local changes will be overwritten.

Returns:

self

fields = ['api_id', 'email', 'initiator', 'token', 'status', <gofigr.models.Timestamp object>, <gofigr.models.Timestamp object>, 'membership_type']
class gofigr.models.JSONField(name, parent=None, derived=False)[source]

Bases: Field

Represents a field that stores JSON primitives.

clone()[source]

Creates a clone of this field.

Returns:

cloned field

to_internal_value(gf, data)[source]

Parses the value of this field from JSON primitives.

Parameters:
  • gf – GoFigr instance

  • data – parsed JSON primitives

Returns:

parsed value

to_representation(value)[source]

Converts the value of this field to a JSON-serializable primitive

class gofigr.models.LinkSharingStatus(enabled)[source]

Bases: NestedMixin

Stores the status of link sharing for shareable objects.

classmethod from_json(data)[source]

Parses this object from JSON

to_json()[source]

Converts this object to JSON

class gofigr.models.LinkedEntityCollection(entities, read_only=False, backlink_property=None, backlink=None)[source]

Bases: object

Represents a collection of linked entities, i.e. figures inside an analysis

create(new_obj, **kwargs)[source]

Creates a new object and appends it to the collection.

Parameters:

new_obj – object to create

Returns:

created object

find(**kwargs)[source]

Returns the first object whose attributes match the query. E.g. find(name=’hello’, age=21) will return all objects where obj.name == “hello” and obj.age == 21.

Parameters:

kwargs – query

Returns:

first object that matches the query or None

find_or_create(default_obj=None, **kwargs)[source]

Finds an object that matches query parameters. If the object doesn’t exist, it will persist default_obj and return it instead.

Parameters:
  • default_obj – object to create/persist if no matches are found

  • kwargs – query parameters. See .find()

Returns:

found or created object.

class gofigr.models.LinkedEntityField(name, entity_type, many=False, read_only=False, backlink_property=None, parent=None, derived=False, sort_key=None, nested=False)[source]

Bases: Field

Represents a linked entity (or a collection of them), e.g. an Analysis inside a Workspace.

clone()[source]

Creates a clone of this field.

Returns:

cloned field

to_internal_value(gf, data)[source]

Parses the value of this field from JSON primitives.

Parameters:
  • gf – GoFigr instance

  • data – parsed JSON primitives

Returns:

parsed value

to_representation(value)[source]

Converts the value of this field to a JSON-serializable primitive

class gofigr.models.LogItem(username, timestamp, action, target_id, target_type, deleted_sentinel=None, deleted=False, thumbnail=None, target_name=None, analysis_id=None, analysis_name=None, api_id=None, gf=None, parent=None)[source]

Bases: NestedMixin

Represents an activity item, such as a figure being created or modified.

fetch()[source]

Fetches information about this log item from the server. API ID and parent have to be set.

classmethod from_json(data, gf=None, parent=None)[source]

Parses this object from JSON

to_json()[source]

Converts this object to JSON

class gofigr.models.LogsMixin[source]

Bases: object

Mixin for entities which support the /log/ endpoint.

get_logs()[source]

Retrieves the activity log.

Returns:

list of LogItem objects.

class gofigr.models.MembersMixin[source]

Bases: object

Mixin for entities which support the /members/ endpoint.

add_member(username, membership_type)[source]

Adds a member to this workspace.

Parameters:
  • username – username of the person to add

  • membership_type – WorkspaceMembership value, e.g. WorkspaceMembership.CREATOR

Returns:

WorkspaceMember instance

change_membership(username, membership_type)[source]

Changes the membership level for a user.

Parameters:
  • username – username

  • membership_type – new membership type, e.g. WorkspaceMembership.CREATOR

Returns:

WorkspaceMember instance

get_members(unauthorized_error=True)[source]

Gets members of this workspace.

Parameters:

unauthorized_error – whether to raise an exception if unauthorized

Returns:

list of WorkspaceMember objects

remove_member(username)[source]

Removes a member from this workspace.

Parameters:

username – username

Returns:

WorkspaceMember instance

class gofigr.models.MembershipInfo(username, membership_type)[source]

Bases: NestedMixin

Stores information about a member of a workspace

classmethod from_json(data)[source]

Parses this object from JSON

to_json()[source]

Converts this object to JSON

class gofigr.models.MetadataProxyField(name, default=None)[source]

Bases: object

Field which is embedded inside the JSON metadata

class gofigr.models.ModelMixin(api_id=None, parse=False, **kwargs)[source]

Bases: ABC

Base class for GoFigr API entities: workspaces, analyses, figures, etc.

property app_url

Gets the URL to this object in the GoFigr web app

property client

Returns the underlying GoFigr instance

create(update=False)[source]

Creates this object on the server.

Parameters:

update – if True and the object already exists, its properties will be updated on the server. Otherwise trying to create an object which already exists will throw an exception.

Returns:

self

delete(**kwargs)[source]

Deletes an object on the server. This cannot be undone.

Parameters:

kwargs – specify delete=True to actually delete the object.

Returns:

endpoint = None
fetch()[source]

Updates all fields from the server. Note that any unsaved local changes will be overwritten.

Returns:

self

fields = ['api_id', '_shallow']
classmethod from_json(data)[source]

Parses an instance of this class from JSON data

include_if_none = []
classmethod list()[source]

Lists all objects from the server.

save(create=False, patch=False, silent=False)[source]

Saves this object to server

Parameters:
  • create – will create the object if it doesn’t already exist. Otherwise, saving a non-existing object will throw an exception.

  • patch – if True, will submit a partial update where some required properties may be missing. You will almost never use this: it’s only useful if for some reason you can’t/don’t want to fetch the full object before updating properties. However, the web app relies on this functionality so it’s available.

  • silent – if True, the server will not generate an activity for this update.

Returns:

self

to_json(include_derived=True, include_none=False)[source]

Serializes this model to JSON primitives.

Parameters:
  • include_derived – if True, derived fields will be included in the representation

  • include_none – if True, fields set to None will be included in the representation

Returns:

this object (and all nested/referenced fields) serialized to JSON primitives.

class gofigr.models.NestedMixin[source]

Bases: ABC

Nested objects: these are not standalone (cannot be manipulated based on API ID), but are directly embedded inside other objects.

classmethod from_json(data)[source]

Parses this object from JSON

to_json()[source]

Converts this object to JSON

class gofigr.models.OrganizationMembership[source]

Bases: ABC

Enum for organizational membership

ALL_LEVELS = ['org_admin', 'workspace_admin', 'workspace_creator', 'workspace_viewer']
ORG_ADMIN = 'org_admin'
WORKSPACE_ADMIN = 'workspace_admin'
WORKSPACE_CREATOR = 'workspace_creator'
WORKSPACE_VIEWER = 'workspace_viewer'
class gofigr.models.Recents(analyses, figures, assets)

Bases: tuple

analyses

Alias for field number 0

assets

Alias for field number 2

figures

Alias for field number 1

class gofigr.models.RevisionMixin(api_id=None, parse=False, **kwargs)[source]

Bases: ShareableModelMixin

Base class for revisions, e.g. FigureRevision or AssetRevision

create(update=False)[source]

Creates a Revision on the server.

Parameters:

update – True to update the object if it already exists

Returns:

self

fetch(fetch_data=True)[source]

Overrides the default fetch to retrieve the data objects (with byte payload) as well. This override is necessary because the API only returns shallow data objects by default.

Parameters:

fetch_data – whether to retrieve full data objects

Returns:

self

fetch_data()[source]

Fetches all data objects

save(create=False, patch=False, silent=False)[source]

Saves this object to server

Parameters:
  • create – will create the object if it doesn’t already exist. Otherwise, saving a non-existing object will throw an exception.

  • patch – if True, will submit a partial update where some required properties may be missing. You will almost never use this: it’s only useful if for some reason you can’t/don’t want to fetch the full object before updating properties. However, the web app relies on this functionality so it’s available.

  • silent – if True, the server will not generate an activity for this update.

Returns:

self

wait_for_processing(timeout=60.0, poll_interval=0.5)[source]

Waits for the revision to finish processing by polling is_processing every poll_interval seconds until it becomes False or the timeout is reached.

Parameters:
  • timeout – Maximum time to wait in seconds (default: 60.0)

  • poll_interval – Time between checks in seconds (default: 0.5)

Returns:

self

Raises:

TimeoutError – If processing doesn’t complete within the timeout period

class gofigr.models.ShareableModelMixin(api_id=None, parse=False, **kwargs)[source]

Bases: ModelMixin

Mixins for things we can share: analyses, figures, revisions, etc.

Gets current status of link sharing

Returns:

true if link sharing is enabled, false otherwise.

get_sharing_users()[source]

Gets a list of all users with whom this object has been shared.

Returns:

list of SharingUserData objects.

Enabled or disables link sharing.

Parameters:

enabled – true to enable, false to disable.

Returns:

confirmation of link sharing status (true or false)

share(username)[source]

Shares this object with a specific user.

Parameters:

username – name of the user to share with.

Returns:

SharingUserData object

unshare(username)[source]

Unshares this object from a user.

Parameters:

username – username of a user from whom to remove access

Returns:

SharingUserData

class gofigr.models.SharingUserData(username, sharing_enabled)[source]

Bases: NestedMixin

Stores information about a user that an object has been shared with

classmethod from_json(data)[source]

Parses this object from JSON

to_json()[source]

Converts this object to JSON

class gofigr.models.ThumbnailMixin[source]

Bases: object

Mixin for entities which support the /log/ endpoint.

get_thumbnail(size)[source]

Retrieves the thumbnail image. :param size: size in pixels

Returns:

PIL.Image if available or None

class gofigr.models.Timestamp(name, parent=None, derived=False)[source]

Bases: Field

Timestamp field

clone()[source]

Creates a clone of this field.

Returns:

cloned field

to_internal_value(gf, data)[source]

Parses the value of this field from JSON primitives.

Parameters:
  • gf – GoFigr instance

  • data – parsed JSON primitives

Returns:

parsed value

to_representation(value)[source]

Converts the value of this field to a JSON-serializable primitive

class gofigr.models.WorkspaceMembership[source]

Bases: ABC

Enum for levels of workspace membership: owner, viewer, etc.

ADMIN = 'admin'
ALL_LEVELS = ['owner', 'admin', 'creator', 'viewer']
CREATOR = 'creator'
OWNER = 'owner'
VIEWER = 'viewer'
class gofigr.models.WorkspaceType[source]

Bases: ABC

Enum for workspace type

PRIMARY = 'primary'
SECONDARY = 'secondary'
class gofigr.models.gf_Analysis(api_id=None, parse=False, **kwargs)[source]

Bases: ShareableModelMixin, LogsMixin, ThumbnailMixin

Represents an analysis

endpoint = 'analysis/'
fields = ['api_id', '_shallow', 'name', 'description', 'size_bytes', <gofigr.models.LinkedEntityField object>, <gofigr.models.LinkedEntityField object>, 'created_by', <gofigr.models.Timestamp object>, 'updated_by', <gofigr.models.Timestamp object>, 'child_updated_by', <gofigr.models.Timestamp object>]
get_figure(name, create=True, **kwargs)[source]

Finds a figure by name, optionally creating it.

Parameters:
  • name – name of the figure to find

  • create – True to create the figure if it doesn’t exist.

  • kwargs – parameters to Figure (e.g. description) if it needs to be created

Returns:

Figure instance

class gofigr.models.gf_ApiKey(api_id=None, parse=False, **kwargs)[source]

Bases: ModelMixin

Represents an API key. The field ‘token’ is the actual token used to authenticate, and is always null except at key creation.

endpoint = 'api_key/'
fetch_and_preserve_token()[source]

Like fetch(), but preserves the token if present. This is useful because the token is only available at creation, so calling fetch() will always set it to None.

Returns:

fields = ['api_id', 'name', 'token', <gofigr.models.Timestamp object>, <gofigr.models.Timestamp object>, <gofigr.models.Timestamp object>, <gofigr.models.LinkedEntityField object>]
class gofigr.models.gf_Asset(api_id=None, parse=False, **kwargs)[source]

Bases: ShareableModelMixin, ThumbnailMixin

Represents an asset, e.g. a file or a dataset

endpoint = 'asset/'
fields = ['api_id', 'name', 'description', 'size_bytes', <gofigr.models.LinkedEntityField object>, <gofigr.models.LinkedEntityField object>, <gofigr.models.LinkedEntityField object>, 'created_by', <gofigr.models.Timestamp object>, 'updated_by', <gofigr.models.Timestamp object>, 'child_updated_by', <gofigr.models.Timestamp object>]
classmethod find_by_name(name, analysis=None)[source]

Finds an asset by name.

Parameters:
  • name – name to search for

  • analysis – optional analysis API ID to scope the search

Returns:

Asset instances, or empty list if not found

class gofigr.models.gf_AssetLinkedToFigure(api_id=None, parse=False, **kwargs)[source]

Bases: ModelMixin

Many-to-many relationship between figure and asset revisions

endpoint = None
fields = ['use_type', <gofigr.models.LinkedEntityField object>, <gofigr.models.LinkedEntityField object>]
class gofigr.models.gf_AssetRevision(api_id=None, parse=False, **kwargs)[source]

Bases: RevisionMixin, ThumbnailMixin

Represents a figure revision

endpoint = 'asset_revision/'
fields = ['api_id', 'revision_index', 'size_bytes', 'is_processing', <gofigr.models.JSONField object>, <gofigr.models.LinkedEntityField object>, <gofigr.models.LinkedEntityField object>, <gofigr.models.DataField object>, 'created_by', <gofigr.models.Timestamp object>, 'updated_by', <gofigr.models.Timestamp object>]
classmethod find_by_hash(digest, hash_type='blake3', analysis=None)[source]

Finds an asset revision by its hash.

Parameters:
  • digest – digest hash (text)

  • hash_type – type of hash (only blake3 supported)

  • analysis – optional analysis API ID to scope the search. When provided, only revisions whose parent asset belongs to that analysis are returned. When None (default), returns all matching revisions workspace-wide, including both scoped and unscoped assets. Note: this does NOT filter to unscoped-only assets.

Returns:

list of matching asset revisions, or empty list if not found

class gofigr.models.gf_CodeData(contents=None, **kwargs)[source]

Bases: gf_Data

Serialized code data (it’s text, but stored and transmitted as bytes)

DATA_TYPE = 'code'
property contents

Code contents.

Returns:

encoding

Field which is embedded inside the JSON metadata

format

Field which is embedded inside the JSON metadata

language

Field which is embedded inside the JSON metadata

metadata_fields = [<gofigr.models.MetadataProxyField object>, <gofigr.models.MetadataProxyField object>, <gofigr.models.MetadataProxyField object>]
class gofigr.models.gf_Data(*args, **kwargs)[source]

Bases: ModelMixin

Represents binary data (e.g. image data, serialized dataframes, etc.)

DATA_TYPE = None
SPECIALIZED_TYPES = None
calculate_hash(hash_type='blake3')[source]

Calculates the hash of the instance’s data.

Parameters:

hash_type (str, optional) – The type of hash algorithm to use. Defaults to “blake3”. Currently, only “blake3” is supported.

Returns:

The hexadecimal representation of the hash if data exists, otherwise None.

Return type:

str or None

Raises:

ValueError – If an unsupported hash_type is specified.

endpoint = 'data/'
fields = ['api_id', 'name', 'type', 'hash', 'size_bytes', 'is_clean_room', <gofigr.models.JSONField object>, <gofigr.models.Base64Field object>]
get_storage_info()[source]

Gets the storage information for this workspace/organization.

Returns:

FlexibleStorateInfo instance

property is_shallow

True if this is a shallow data object without the byte payload

property local_id

Reserved for internal API use

metadata_fields = []
specialize()[source]

Creates a specialized data instance, e.g. ImageData, based on the data type

class gofigr.models.gf_Figure(api_id=None, parse=False, **kwargs)[source]

Bases: ShareableModelMixin, ThumbnailMixin

Represents a figure

endpoint = 'figure/'
fields = ['api_id', '_shallow', 'name', 'description', 'size_bytes', <gofigr.models.LinkedEntityField object>, <gofigr.models.LinkedEntityField object>, 'created_by', <gofigr.models.Timestamp object>, 'updated_by', <gofigr.models.Timestamp object>, 'child_updated_by', <gofigr.models.Timestamp object>]
class gofigr.models.gf_FileData(*args, **kwargs)[source]

Bases: gf_Data

Binary file data

DATA_TYPE = 'file'
metadata_fields = [<gofigr.models.MetadataProxyField object>]
path

Field which is embedded inside the JSON metadata

classmethod read(path)[source]

Creates a new FileData object from the contents of a file.

Parameters:

path – path of the file to read

Returns:

FileData object

write(path)[source]

Writes the contents of this file to the given path

class gofigr.models.gf_ImageData(*args, **kwargs)[source]

Bases: gf_Data

Binary image data

DATA_TYPE = 'image'
format

Field which is embedded inside the JSON metadata

property image

Returns this image as a PIL.Image object.

Returns:

PIL.Image

property is_interactive

True if this figure is interactive, false otherwise

is_watermarked

Field which is embedded inside the JSON metadata

metadata_fields = [<gofigr.models.MetadataProxyField object>, <gofigr.models.MetadataProxyField object>]
class gofigr.models.gf_MetadataProxy(api_id=None, parse=False, **kwargs)[source]

Bases: ModelMixin

Represents a proxy object for sharing metadata between the GoFigr extension (server-side) and the Jupyter client.

delete(**kwargs)[source]

Deletes an object on the server. This cannot be undone.

Parameters:

kwargs – specify delete=True to actually delete the object.

Returns:

endpoint = 'metadata/'
fetch()[source]

Updates all fields from the server. Note that any unsaved local changes will be overwritten.

Returns:

self

fields = ['api_id', 'initiator', 'token', <gofigr.models.Timestamp object>, <gofigr.models.Timestamp object>, <gofigr.models.Timestamp object>, <gofigr.models.JSONField object>]
save(*args, **kwargs)[source]

Saves this object to server

Parameters:
  • create – will create the object if it doesn’t already exist. Otherwise, saving a non-existing object will throw an exception.

  • patch – if True, will submit a partial update where some required properties may be missing. You will almost never use this: it’s only useful if for some reason you can’t/don’t want to fetch the full object before updating properties. However, the web app relies on this functionality so it’s available.

  • silent – if True, the server will not generate an activity for this update.

Returns:

self

update_metadata(metadata)[source]

Accepts this invitation

class gofigr.models.gf_Organization(api_id=None, parse=False, **kwargs)[source]

Bases: ModelMixin, LogsMixin, MembersMixin, FlexibleStorageMixin

Represents an organization

endpoint = 'organization/'
fields = ['api_id', 'name', 'email', 'description', 'allow_per_workspace_storage_settings', <gofigr.models.Base64Field object>, <gofigr.models.LinkedEntityField object>]
get_invitations()[source]

Gets members of this workspace.

Returns:

list of WorkspaceMember objects

property logo_image

Returns the logo as a PIL.Image, or None if not set.

class gofigr.models.gf_OrganizationInvitation(api_id=None, parse=False, **kwargs)[source]

Bases: InvitationMixin

Represents an invitation to join an organization.

endpoint = 'invitations/organization/'
fields = ['api_id', 'email', 'initiator', 'token', 'status', <gofigr.models.Timestamp object>, <gofigr.models.Timestamp object>, 'membership_type', <gofigr.models.LinkedEntityField object>]
class gofigr.models.gf_Revision(*args, **kwargs)[source]

Bases: RevisionMixin, ThumbnailMixin

Represents a figure revision

property code_data

Returns only code data (if any)

endpoint = 'revision/'
fields = ['api_id', 'revision_index', 'size_bytes', 'is_processing', 'is_clean_room', <gofigr.models.JSONField object>, <gofigr.models.LinkedEntityField object>, <gofigr.models.LinkedEntityField object>, <gofigr.models.DataField object>, 'created_by', <gofigr.models.Timestamp object>, 'updated_by', <gofigr.models.Timestamp object>]
property file_data

Returns only file data (if any)

property image_data

Returns only image data (if any)

property revision_url

Returns the GoFigr URL for this revision, using the short ID when available.

property table_data

Returns only DataFrame data (if any)

property text_data

Returns only text data (if any)

class gofigr.models.gf_TableData(dataframe=None, **kwargs)[source]

Bases: gf_Data

Serialized data frame

DATA_TYPE = 'dataframe'
property dataframe

Parses the dataframe from the embedded stream of bytes.

Returns:

pd.DataFrame or None

encoding

Field which is embedded inside the JSON metadata

format

Field which is embedded inside the JSON metadata

metadata_fields = [<gofigr.models.MetadataProxyField object>, <gofigr.models.MetadataProxyField object>]
class gofigr.models.gf_TextData(contents=None, **kwargs)[source]

Bases: gf_Data

Serialized text data (even though it’s text, we store and transmit bytes)

DATA_TYPE = 'text'
property contents

Decoded text (a string)

encoding

Field which is embedded inside the JSON metadata

format

Field which is embedded inside the JSON metadata

metadata_fields = [<gofigr.models.MetadataProxyField object>, <gofigr.models.MetadataProxyField object>]
class gofigr.models.gf_Workspace(api_id=None, parse=False, **kwargs)[source]

Bases: ModelMixin, LogsMixin, MembersMixin, FlexibleStorageMixin

Represents a workspace

endpoint = 'workspace/'
fields = ['api_id', '_shallow', 'name', 'description', 'workspace_type', 'size_bytes', <gofigr.models.LinkedEntityField object>, <gofigr.models.LinkedEntityField object>, <gofigr.models.LinkedEntityField object>, 'created_by', <gofigr.models.Timestamp object>, 'updated_by', <gofigr.models.Timestamp object>, 'child_updated_by', <gofigr.models.Timestamp object>]
get_analysis(name, create=True, **kwargs)[source]

Finds an analysis by name.

Parameters:
  • name – name of the analysis

  • create – whether to create an analysis if one doesn’t exist

  • kwargs – if an Analysis needs to be created, parameters of the Analysis object (such as description)

Returns:

Analysis instance.

get_invitations()[source]

Gets members of this workspace.

Returns:

list of WorkspaceMember objects

get_recents(limit=100)[source]

Gets the most recently created or modified analyses & figures.

Parameters:

limit – maximum number of elements to retrieve.

Returns:

Instance of the Recents object

include_if_none = ['organization']
class gofigr.models.gf_WorkspaceInvitation(api_id=None, parse=False, **kwargs)[source]

Bases: InvitationMixin

Represents an invitation to join a workspace.

endpoint = 'invitations/workspace/'
fields = ['api_id', 'email', 'initiator', 'token', 'status', <gofigr.models.Timestamp object>, <gofigr.models.Timestamp object>, 'membership_type', <gofigr.models.LinkedEntityField object>]

gofigr.watermarks module

Copyright (c) 2022, Flagstaff Solutions, LLC All rights reserved.

class gofigr.watermarks.DefaultWatermark(show_qr_code=True, margin_px=10, qr_background=(255, 255, 255, 255), qr_foreground=(0, 0, 0, 153), qr_scale=2, font=None)[source]

Bases: object

Draws QR codes + URL watermark on figures.

apply(image, revision)[source]

Adds a QR watermark to an image.

Parameters:
  • image – PIL.Image

  • revision – instance of FigureRevision

Returns:

PIL.Image containing the watermarked image

draw_identifier(text)[source]

Draws the GoFigr identifier text, returning it as a PIL image

draw_table(pairs, padding_x=10, padding_y=10, border_width=1)[source]

Draws key-value pairs as a table, returning it as a PIL image.

get_watermark(revision)[source]

Generates just the watermark for a revision.

Parameters:

revision – FigureRevision

Returns:

PIL.Image

get_watermark_height()[source]

Return the pixel height of the watermark strip.

pad_for_watermark(image)[source]

Add blank vertical space below the image matching the watermark height. Only pads height, not width, so the preview matches the published image size regardless of watermark URL length.

class gofigr.watermarks.Watermark[source]

Bases: object

Base class for drawing watermaks on figures.

apply(image, revision)[source]

Places a watermark on an image

Parameters:
  • image – PIL Image object

  • revision – GoFigr revision object

gofigr.watermarks.add_margins(img, margins)[source]

Adds margins to an image

gofigr.watermarks.stack_horizontally(*images, alignment='center')[source]

Stacks images horizontally. Thanks, Stack Overflow!

https://stackoverflow.com/questions/30227466/combine-several-images-horizontally-with-python

gofigr.watermarks.stack_vertically(*images, alignment='center')[source]

Stacks images vertically.

gofigr.annotators module

Copyright (c) 2023, Flagstaff Solutions, LLC All rights reserved.

class gofigr.annotators.Annotator[source]

Bases: ABC

Annotates figure revisions with pertinent information, such as cell code, variable values, etc.

annotate(revision)[source]

Annotates a figure revision in-place.

Parameters:

revision – revision to annotate

Returns:

annotated revision (same object as input).

class gofigr.annotators.BackendAnnotator[source]

Bases: Annotator

Annotates revisions with the python version & the kernel info

annotate(revision)[source]

Annotates a figure revision in-place.

Parameters:

revision – revision to annotate

Returns:

annotated revision (same object as input).

class gofigr.annotators.CellCodeAnnotator[source]

Bases: IPythonAnnotator

Annotates revisions with cell contents

annotate_ip(revision, ext)[source]

Annotates the figure revision assuming the IPython extension is available.

Parameters:
  • revision – GoFigr revision

  • ext – Jupyter extension

Returns:

annotated revision

class gofigr.annotators.CellIdAnnotator[source]

Bases: IPythonAnnotator

Annotates revisions with the ID of the Jupyter cell

annotate_ip(revision, ext)[source]

Annotates the figure revision assuming the IPython extension is available.

Parameters:
  • revision – GoFigr revision

  • ext – Jupyter extension

Returns:

annotated revision

class gofigr.annotators.EnvironmentAnnotator[source]

Bases: Annotator

Annotates revisions with the python version & the kernel info

annotate(revision)[source]

Annotates a figure revision in-place.

Parameters:

revision – revision to annotate

Returns:

annotated revision (same object as input).

class gofigr.annotators.GitAnnotator[source]

Bases: Annotator

Annotates revisions with Git information

annotate(revision)[source]

Generates a link for the current commit of a local repository.

class gofigr.annotators.HistoryAnnotator[source]

Bases: Annotator

Annotates revisions with IPython execution history

annotate(revision)[source]

Annotates a figure revision in-place.

Parameters:

revision – revision to annotate

Returns:

annotated revision (same object as input).

class gofigr.annotators.IPythonAnnotator[source]

Bases: Annotator

Annotates figures within the IPython/Jupyter environment.

annotate(revision)[source]

Annotates the figure revision.

Parameters:

revision – FigureRevision

Returns:

annotated FigureRevision

annotate_ip(revision, ext)[source]

Annotates the figure revision assuming the IPython extension is available.

Parameters:
  • revision – GoFigr revision

  • ext – Jupyter extension

Returns:

annotated revision

get_ip_extension()[source]
Returns:

IPython extension if available, None otherwise.

class gofigr.annotators.NotebookMetadataAnnotator[source]

Bases: IPythonAnnotator

Annotates revisions with notebook metadata, including filename & path, as well as the full URL

annotate(revision, sync=True)[source]

Annotates the figure revision.

Parameters:

revision – FigureRevision

Returns:

annotated FigureRevision

parse_metadata(error=True)[source]

Returns notebook metadata, raising an error if not available and error=True.

Parameters:

error – if True, will raise an error if metadata is not available

try_get_metadata()[source]

Infers the notebook path & name using currently available metadata if possible, returning None otherwise

class gofigr.annotators.NotebookNameAnnotator(*args, **kwargs)[source]

Bases: NotebookMetadataAnnotator

(Deprecated) Annotates revisions with notebook name & path

class gofigr.annotators.PipFreezeAnnotator(cache=True)[source]

Bases: Annotator

Annotates revisions with the output of pip freeze

annotate(revision)[source]

Annotates a figure revision in-place.

Parameters:

revision – revision to annotate

Returns:

annotated revision (same object as input).

class gofigr.annotators.ScriptAnnotator[source]

Bases: Annotator

Annotates revisions with the code of the running script

annotate(revision)[source]

Annotates a figure revision in-place.

Parameters:

revision – revision to annotate

Returns:

annotated revision (same object as input).

class gofigr.annotators.SystemAnnotator[source]

Bases: Annotator

Annotates revisions with the OS version

annotate(revision)[source]

Annotates a figure revision in-place.

Parameters:

revision – revision to annotate

Returns:

annotated revision (same object as input).

gofigr.widget module

Copyright (c) 2024, Flagstaff Solutions, LLC All rights reserved.

class gofigr.widget.AssetWidget(rev)[source]

Bases: WidgetBase

Generates a GoFigr startup widget

Gets the app link to a GoFigr object

show()[source]

Renders this widget in Jupyter by generating the HTML/JS & calling display()

class gofigr.widget.CompactWidget(revision)[source]

Bases: RevisionWidgetBase

Generates a compact GoFigr widget

show()[source]

Renders this widget in Jupyter by generating the HTML/JS & calling display()

class gofigr.widget.DetailedWidget(revision)[source]

Bases: RevisionWidgetBase

Generates HTML/Javascript for the GoFigr Jupyter widget shown under each figure

show()[source]

Renders this widget in Jupyter by generating the HTML/JS & calling display()

class gofigr.widget.LiteStartupWidget(extension)[source]

Bases: WidgetBase

Generates a GoFigr startup widget

show()[source]

Renders this widget in Jupyter by generating the HTML/JS & calling display()

class gofigr.widget.MinimalWidget(revision)[source]

Bases: RevisionWidgetBase

Generates a compact GoFigr widget

show()[source]

Renders this widget in Jupyter by generating the HTML/JS & calling display()

class gofigr.widget.RevisionWidgetBase(revision)[source]

Bases: WidgetBase, ABC

Generates HTML/Javascript for the GoFigr Jupyter widget shown under each figure

Generates HTML/JS for the copy image button

Generates HTML for the download link

Generates HTML/JS for the copy link button

class gofigr.widget.StartupWidget(extension)[source]

Bases: WidgetBase

Generates a GoFigr startup widget

Gets the app link to a GoFigr object

show()[source]

Renders this widget in Jupyter by generating the HTML/JS & calling display()

class gofigr.widget.WidgetBase[source]

Bases: ABC

Generates HTML/Javascript for the GoFigr Jupyter widget shown under each figure

get_logo_b64()[source]

Reads the GoFigr logo and returns it as a base64 string

show()[source]

Displays the widget in Jupyter

gofigr.widget.display(obj, *args, **kwargs)[source]

Wrapper around IPython’s display function. Ignores output if running non-interactively.

gofigr.widget.timestamp_to_local_tz(dt_tz)[source]

Converts a datetime to the local timezone

gofigr.backends module

Copyright (c) 2023, Flagstaff Solutions, LLC All rights reserved.

class gofigr.backends.GoFigrBackend[source]

Bases: ABC

Base class for figure backends, e.g. matplotlib or plotly

add_interactive_watermark(fig, rev, watermark)[source]

Adds watermark to a figure using the backend’s native objects (if supported by the backend)

Parameters:
  • fig – figure to watermark

  • rev – FigureRevision object

  • watermark – DefaultWatermark instance

Returns:

modified figure

close(fig)[source]

Closes a figure and prevents it from being displayed. :param fig: figure to close :return: None

figure_to_bytes(fig, fmt, params)[source]

Given a figure and an image format, converts the figure to binary representation in that format.

Parameters:
  • fig – figure object

  • fmt – format, e.g. png

  • params – backend-specific parameters

Returns:

bytes

figure_to_html(fig)[source]

Converts a figure to interactive HTML (if supported by the backend)

Parameters:

fig – figure to convert to HTML

Returns:

figure as HTML string

find_figures(shell, data)[source]

Finds all figures compatible with this backend in the current environment.

Parameters:

shell – IPython shell

Returns:

iterator over available figures

get_backend_name()[source]

Gets a human-readable name of this backend. :return: backend name, a string

get_default_figure(silent=False)[source]

Returns the default/current figure, e.g. plt.gcf() for matplotlib

Parameters:

silent – if True, will suppress warnings/errors if default figure is unavailable

get_supported_image_formats()[source]

Gets a list of supported image formats

get_title(fig)[source]

Extracts figure title

Parameters:

fig – figure to extract title from

Returns:

figure title, or None if not available

is_compatible(fig)[source]

Returns True if this backend is compatible with a figure

is_interactive(fig)[source]

Returns True if the figure supports interactive (HTML) output

is_static(fig)[source]

Returns True if the figure is static (e.g. an image)

gofigr.backends.get_all_function_arguments(frame)[source]

Iterates over all function arguments, including *args and **kwargs

gofigr.backends.get_backend(figure, backends)[source]

Gets the backend compatible with a figure

Parameters:
  • figure – figure to find a backend for

  • backends – list of backends to search

Returns:

GoFigr backend compatible with the figure, or ValueError if none are compatible.

gofigr.backends.matplotlib module

Copyright (c) 2023, Flagstaff Solutions, LLC All rights reserved.

class gofigr.backends.matplotlib.MatplotlibBackend[source]

Bases: GoFigrBackend

MatplotLib backend for GoFigr.

close(fig)[source]

Closes a figure and prevents it from being displayed. :param fig: figure to close :return: None

figure_to_bytes(fig, fmt, params)[source]

Given a figure and an image format, converts the figure to binary representation in that format.

Parameters:
  • fig – figure object

  • fmt – format, e.g. png

  • params – backend-specific parameters

Returns:

bytes

find_figures(shell, data)[source]

Finds all figures compatible with this backend in the current environment.

Parameters:

shell – IPython shell

Returns:

iterator over available figures

get_backend_name()[source]

Gets a human-readable name of this backend. :return: backend name, a string

get_default_figure(silent=False)[source]

Returns the default/current figure, e.g. plt.gcf() for matplotlib

Parameters:

silent – if True, will suppress warnings/errors if default figure is unavailable

get_supported_image_formats()[source]

Gets a list of supported image formats

get_title(fig)[source]

Extracts figure title

Parameters:

fig – figure to extract title from

Returns:

figure title, or None if not available

is_compatible(fig)[source]

Returns True if this backend is compatible with a figure

is_interactive(fig)[source]

Returns True if the figure supports interactive (HTML) output

static title_to_string(title)[source]

Extracts the title as a string from a title-like object (e.g. Text)

class gofigr.backends.matplotlib.SuppressPltWarnings[source]

Bases: object

Temporarily suppresses matplotlib warnings.

gofigr.backends.plotly module

Copyright (c) 2023, Flagstaff Solutions, LLC All rights reserved.

class gofigr.backends.plotly.PlotlyBackend[source]

Bases: GoFigrBackend

Plotly backend for GoFigr

add_interactive_watermark(fig, rev, watermark)[source]

Adds watermark to a figure using the backend’s native objects (if supported by the backend)

Parameters:
  • fig – figure to watermark

  • rev – FigureRevision object

  • watermark – DefaultWatermark instance

Returns:

modified figure

close(fig)[source]

Closes a figure and prevents it from being displayed. :param fig: figure to close :return: None

figure_to_bytes(fig, fmt, params)[source]

Given a figure and an image format, converts the figure to binary representation in that format.

Parameters:
  • fig – figure object

  • fmt – format, e.g. png

  • params – backend-specific parameters

Returns:

bytes

figure_to_html(fig)[source]

Converts a figure to interactive HTML (if supported by the backend)

Parameters:

fig – figure to convert to HTML

Returns:

figure as HTML string

find_figures(shell, data)[source]

Finds all figures compatible with this backend in the current environment.

Parameters:

shell – IPython shell

Returns:

iterator over available figures

get_backend_name()[source]

Gets a human-readable name of this backend. :return: backend name, a string

get_default_figure(silent=False)[source]

Returns the default/current figure, e.g. plt.gcf() for matplotlib

Parameters:

silent – if True, will suppress warnings/errors if default figure is unavailable

get_supported_image_formats()[source]

Gets a list of supported image formats

get_title(fig)[source]

Extracts figure title

Parameters:

fig – figure to extract title from

Returns:

figure title, or None if not available

is_compatible(fig)[source]

Returns True if this backend is compatible with a figure

is_interactive(fig)[source]

Returns True if the figure supports interactive (HTML) output

gofigr.backends.plotnine module

Copyright (c) 2024, Flagstaff Solutions, LLC All rights reserved.

class gofigr.backends.plotnine.PlotnineBackend[source]

Bases: GoFigrBackend

MatplotLib backend for GoFigr.

close(fig)[source]

Closes a figure and prevents it from being displayed. :param fig: figure to close :return: None

figure_to_bytes(fig, fmt, params)[source]

Given a figure and an image format, converts the figure to binary representation in that format.

Parameters:
  • fig – figure object

  • fmt – format, e.g. png

  • params – backend-specific parameters

Returns:

bytes

find_figures(shell, data)[source]

Finds all figures compatible with this backend in the current environment.

Parameters:

shell – IPython shell

Returns:

iterator over available figures

get_backend_name()[source]

Gets a human-readable name of this backend. :return: backend name, a string

get_default_figure(silent=False)[source]

Returns the default/current figure, e.g. plt.gcf() for matplotlib

Parameters:

silent – if True, will suppress warnings/errors if default figure is unavailable

get_supported_image_formats()[source]

Gets a list of supported image formats

get_title(fig)[source]

Extracts figure title

Parameters:

fig – figure to extract title from

Returns:

figure title, or None if not available

is_compatible(fig)[source]

Returns True if this backend is compatible with a figure

is_interactive(fig)[source]

Returns True if the figure supports interactive (HTML) output

gofigr.backends.py3dmol module

Copyright (c) 2023, Flagstaff Solutions, LLC All rights reserved.

class gofigr.backends.py3dmol.Py3DmolBackend(*args, debug=False, image_size=(1920, 1080), disable_logging=True, **kwargs)[source]

Bases: GoFigrBackend

Plotly backend for GoFigr

add_interactive_watermark(fig, rev, watermark)[source]

Adds watermark to a figure using the backend’s native objects (if supported by the backend)

Parameters:
  • fig – figure to watermark

  • rev – FigureRevision object

  • watermark – DefaultWatermark instance

Returns:

modified figure

close(fig)[source]

Closes a figure and prevents it from being displayed. :param fig: figure to close :return: None

figure_to_bytes(fig, fmt, params)[source]

Given a figure and an image format, converts the figure to binary representation in that format.

Parameters:
  • fig – figure object

  • fmt – format, e.g. png

  • params – backend-specific parameters

Returns:

bytes

figure_to_html(fig)[source]

Converts a figure to interactive HTML (if supported by the backend)

Parameters:

fig – figure to convert to HTML

Returns:

figure as HTML string

find_figures(shell, data)[source]

Finds all figures compatible with this backend in the current environment.

Parameters:

shell – IPython shell

Returns:

iterator over available figures

get_backend_name()[source]

Gets a human-readable name of this backend. :return: backend name, a string

get_default_figure(silent=False)[source]

Returns the default/current figure, e.g. plt.gcf() for matplotlib

Parameters:

silent – if True, will suppress warnings/errors if default figure is unavailable

get_supported_image_formats()[source]

Gets a list of supported image formats

get_title(fig)[source]

Extracts figure title

Parameters:

fig – figure to extract title from

Returns:

figure title, or None if not available

is_compatible(fig)[source]

Returns True if this backend is compatible with a figure

is_interactive(fig)[source]

Returns True if the figure supports interactive (HTML) output

class gofigr.backends.py3dmol.WatermarkedView(wrapped_obj, extra_html)[source]

Bases: view

Overrides py3Dmol.view to include a GoFigr watermark