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:
objectProvides 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.
- 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.
- class gofigr.FindByName(name, description=None, create=False)[source]
Bases:
objectUsed 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:
objectThe 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
- 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
- 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
- request(method, endpoint, *, body=None, params=None, response_type=None, expected_status=None, throw_exception=True)[source]
Typed-ish API call, intended for external packages that build on the GoFigr client (e.g. internal tooling, the compute supervisor) without registering their endpoints in this library. Auth, base URL, token refresh, and error mapping come from _request; this method adds dataclass <-> JSON marshalling and a method-as-string signature.
For flat dataclasses, pass a dataclass instance as body and a dataclass class as response_type; the helper will dataclasses.asdict() the body and instantiate response_type from the JSON response. For nested types, lists, or anything else, pass body as a dict and omit response_type – the parsed JSON dict (or None for 204) is returned directly.
- Parameters:
method – HTTP method as a string: ‘GET’ | ‘POST’ | ‘PUT’ | ‘PATCH’ | ‘DELETE’
endpoint – relative API endpoint, e.g. ‘compute/instance/<id>/heartbeat/’
body – dict or dataclass instance; serialized to JSON. Ignored for GET / DELETE.
params – query-string params dict (passed through to requests).
response_type – dataclass class to instantiate from the JSON response, or None to return the dict as-is.
expected_status – int or iterable of acceptable response codes. Defaults to 204 for DELETE, 200 otherwise.
throw_exception – raise on unexpected status (default True).
- Returns:
response_type instance, or parsed JSON, or None for 204.
- 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
- 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:
objectUsed 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:
objectStores 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:
PublisherAdds 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.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:
FieldTimestamp field
- class gofigr.models.CodeLanguage[source]
Bases:
ABCFor 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:
LinkedEntityFieldCustomizes a LinkedEntityField so that the entity data is fully embedded in the representation
- class gofigr.models.DataType[source]
Bases:
ABCEnum 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:
objectDescribes a dynamically created object field, i.e. figure name, revision etc.
- class gofigr.models.FlexibleStorageInfo(vendor, params)[source]
Bases:
NestedMixinStores information required for flexible storage
- class gofigr.models.FlexibleStorageMixin[source]
Bases:
objectMixin 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:
ModelMixinRepresents 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:
FieldRepresents a field that stores JSON primitives.
- class gofigr.models.LinkSharingStatus(enabled)[source]
Bases:
NestedMixinStores the status of link sharing for shareable objects.
- class gofigr.models.LinkedEntityCollection(entities, read_only=False, backlink_property=None, backlink=None)[source]
Bases:
objectRepresents 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:
FieldRepresents 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:
NestedMixinRepresents an activity item, such as a figure being created or modified.
- class gofigr.models.LogsMixin[source]
Bases:
objectMixin for entities which support the /log/ endpoint.
- class gofigr.models.MembersMixin[source]
Bases:
objectMixin 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:
NestedMixinStores information about a member of a workspace
- class gofigr.models.MetadataProxyField(name, default=None)[source]
Bases:
objectField which is embedded inside the JSON metadata
- class gofigr.models.ModelMixin(api_id=None, parse=False, **kwargs)[source]
Bases:
ABCBase 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:
ABCNested 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:
ABCEnum 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:
ShareableModelMixinBase 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
- 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
Bases:
ModelMixinMixins 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:
NestedMixinStores information about a user that an object has been shared with
- class gofigr.models.ThumbnailMixin[source]
Bases:
objectMixin for entities which support the /log/ endpoint.
- class gofigr.models.Timestamp(name, parent=None, derived=False)[source]
Bases:
FieldTimestamp field
- class gofigr.models.WorkspaceMembership[source]
Bases:
ABCEnum 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:
ABCEnum for workspace type
- PRIMARY = 'primary'
- SECONDARY = 'secondary'
- class gofigr.models.gf_Analysis(api_id=None, parse=False, **kwargs)[source]
Bases:
ShareableModelMixin,LogsMixin,ThumbnailMixinRepresents 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:
ModelMixinRepresents 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,ThumbnailMixinRepresents 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>]
- class gofigr.models.gf_AssetLinkedToFigure(api_id=None, parse=False, **kwargs)[source]
Bases:
ModelMixinMany-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,ThumbnailMixinRepresents 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_DataSerialized 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:
ModelMixinRepresents 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 = []
- class gofigr.models.gf_Figure(api_id=None, parse=False, **kwargs)[source]
Bases:
ShareableModelMixin,ThumbnailMixinRepresents 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_DataBinary 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_DataBinary 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:
ModelMixinRepresents 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,FlexibleStorageMixinRepresents an organization
- endpoint = 'organization/'
- fields = ['api_id', 'name', 'email', 'description', 'allow_per_workspace_storage_settings', <gofigr.models.Base64Field object>, <gofigr.models.LinkedEntityField object>]
- 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:
InvitationMixinRepresents 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,ThumbnailMixinRepresents 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_DataSerialized 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_DataSerialized 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,FlexibleStorageMixinRepresents 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:
InvitationMixinRepresents 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:
objectDraws 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_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.
- class gofigr.watermarks.Watermark[source]
Bases:
objectBase 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:
ABCAnnotates figure revisions with pertinent information, such as cell code, variable values, etc.
- class gofigr.annotators.BackendAnnotator[source]
Bases:
AnnotatorAnnotates revisions with the python version & the kernel info
- class gofigr.annotators.CellCodeAnnotator[source]
Bases:
IPythonAnnotatorAnnotates revisions with cell contents
- class gofigr.annotators.CellIdAnnotator[source]
Bases:
IPythonAnnotatorAnnotates revisions with the ID of the Jupyter cell
- class gofigr.annotators.EnvironmentAnnotator[source]
Bases:
AnnotatorAnnotates revisions with the python version & the kernel info
- class gofigr.annotators.GitAnnotator[source]
Bases:
AnnotatorAnnotates revisions with Git information
- class gofigr.annotators.HistoryAnnotator[source]
Bases:
AnnotatorAnnotates revisions with IPython execution history
- class gofigr.annotators.IPythonAnnotator[source]
Bases:
AnnotatorAnnotates 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:
IPythonAnnotatorAnnotates 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
- class gofigr.annotators.NotebookNameAnnotator(*args, **kwargs)[source]
Bases:
NotebookMetadataAnnotator(Deprecated) Annotates revisions with notebook name & path
- class gofigr.annotators.PipFreezeAnnotator(cache=True)[source]
Bases:
AnnotatorAnnotates 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:
WidgetBaseGenerates a GoFigr startup widget
- class gofigr.widget.CompactWidget(revision)[source]
Bases:
RevisionWidgetBaseGenerates a compact GoFigr widget
- class gofigr.widget.DetailedWidget(revision)[source]
Bases:
RevisionWidgetBaseGenerates HTML/Javascript for the GoFigr Jupyter widget shown under each figure
- class gofigr.widget.LiteStartupWidget(extension)[source]
Bases:
WidgetBaseGenerates a GoFigr startup widget
- class gofigr.widget.MinimalWidget(revision)[source]
Bases:
RevisionWidgetBaseGenerates a compact GoFigr widget
- class gofigr.widget.RevisionWidgetBase(revision)[source]
Bases:
WidgetBase,ABCGenerates 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:
WidgetBaseGenerates a GoFigr startup widget
- class gofigr.widget.WidgetBase[source]
Bases:
ABCGenerates HTML/Javascript for the GoFigr Jupyter widget shown under each figure
gofigr.backends module
Copyright (c) 2023, Flagstaff Solutions, LLC All rights reserved.
- class gofigr.backends.GoFigrBackend[source]
Bases:
ABCBase 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:
GoFigrBackendMatplotLib 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:
GoFigrBackendPlotly 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:
GoFigrBackendMatplotLib 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:
GoFigrBackendPlotly 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