gofigr package
Module contents
Copyright (c) 2022, Flagstaff Solutions, LLC All rights reserved.
- 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.
- 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.
- property revisions
Returns all revisions in the log.
- 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 api_url
Full URL to the API endpoint.
- property app_url
Returns the URL to the GoFigr app
- 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. :return: 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
- 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).
- 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
- 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.
- 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
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.
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. :param files: either (a) list of file paths or (b) dictionary of name to file path/file obj :param annotators: list of annotators to use. Defaults to self.annotators
- 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)[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.
- 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.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.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
- 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
- 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.
- class gofigr.models.FlexibleStorageInfo(vendor, params)[source]
Bases:
NestedMixin
Stores information required for flexible storage
- 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
- class gofigr.models.InvitationMixin(api_id=None, parse=False, **kwargs)[source]
Bases:
ModelMixin
Represents an invitation to join a workspace.
- 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.
- class gofigr.models.LinkSharingStatus(enabled)[source]
Bases:
NestedMixin
Stores the status of link sharing for shareable objects.
- 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.
- 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.
- class gofigr.models.LogsMixin[source]
Bases:
object
Mixin for entities which support the /log/ endpoint.
- 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
- class gofigr.models.MembershipInfo(username, membership_type)[source]
Bases:
NestedMixin
Stores information about a member of a workspace
- 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']
- include_if_none = []
- 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.
- 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
- 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
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.
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)
Shares this object with a specific user.
- Parameters:
username – name of the user to share with.
- Returns:
SharingUserData object
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
- class gofigr.models.ThumbnailMixin[source]
Bases:
object
Mixin for entities which support the /log/ endpoint.
- class gofigr.models.Timestamp(name, parent=None, derived=False)[source]
Bases:
Field
Timestamp field
- 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>]
- 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>, 'created_by', <gofigr.models.Timestamp object>, 'updated_by', <gofigr.models.Timestamp object>, 'child_updated_by', <gofigr.models.Timestamp object>]
- 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', <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>]
- 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', <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 = []
- 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
- 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
- class gofigr.models.gf_Organization(api_id=None, parse=False, **kwargs)[source]
Bases:
ModelMixin
,LogsMixin
,MembersMixin
,FlexibleStorageMixin
Represents a workspace
- endpoint = 'organization/'
- fields = ['api_id', 'name', 'email', 'description', 'allow_per_workspace_storage_settings', <gofigr.models.LinkedEntityField object>]
- 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', <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
- 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:
- 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
- metadata_fields = [<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_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=(0, 0, 0, 0), qr_foreground=(0, 0, 0, 153), qr_scale=2, font=None)[source]
Bases:
object
Draws QR codes + URL watermark on figures.
- class gofigr.watermarks.Watermark[source]
Bases:
object
Base class for drawing watermaks on figures.
- 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.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.
- class gofigr.annotators.BackendAnnotator[source]
Bases:
Annotator
Annotates revisions with the python version & the kernel info
- class gofigr.annotators.CellCodeAnnotator[source]
Bases:
IPythonAnnotator
Annotates revisions with cell contents
- class gofigr.annotators.CellIdAnnotator[source]
Bases:
IPythonAnnotator
Annotates revisions with the ID of the Jupyter cell
- class gofigr.annotators.EnvironmentAnnotator[source]
Bases:
Annotator
Annotates revisions with the python version & the kernel info
- class gofigr.annotators.GitAnnotator[source]
Bases:
Annotator
Annotates revisions with Git information
- class gofigr.annotators.HistoryAnnotator[source]
Bases:
Annotator
Annotates revisions with IPython execution history
- 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
- class gofigr.annotators.NotebookMetadataAnnotator[source]
Bases:
IPythonAnnotator
Annotates revisions with notebook metadata, including filename & path, as well as the full URL
- annotate(revision)[source]
Annotates the figure revision.
- Parameters:
revision – FigureRevision
- Returns:
annotated FigureRevision
- 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
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
- class gofigr.widget.CompactWidget(revision)[source]
Bases:
RevisionWidgetBase
Generates a compact GoFigr widget
- class gofigr.widget.DetailedWidget(revision)[source]
Bases:
RevisionWidgetBase
Generates HTML/Javascript for the GoFigr Jupyter widget shown under each figure
- class gofigr.widget.MinimalWidget(revision)[source]
Bases:
RevisionWidgetBase
Generates a compact GoFigr widget
- class gofigr.widget.RevisionWidgetBase(revision)[source]
Bases:
WidgetBase
,ABC
Generates HTML/Javascript for the GoFigr Jupyter widget shown under each figure
- get_copy_link(label, watermark, image_format='png')[source]
Generates HTML/JS for the copy image button
- class gofigr.widget.StartupWidget(extension)[source]
Bases:
WidgetBase
Generates a GoFigr startup widget
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
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
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
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
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