Skip to content

jsonservice

JSONServiceV1(server_address, auth_header, api_version, endpoints, server_name, ngl_url, max_retries=None, pool_maxsize=None, pool_block=None, over_client=None)

Bases: ClientBase

server_version: Optional[Version] property

The version of the service running on the remote server. Note that this refers to the software running on the server and has nothing to do with the version of the datastack itself.

state_service_endpoint property

Endpoint URL for posting JSON state

build_neuroglancer_url(state_id, ngl_url=None, target_site=None, static_url=False, format_properties=False)

Build a URL for a Neuroglancer deployment that will automatically retrieve specified state. If the datastack is specified, this is prepopulated from the info file field "viewer_site". If no ngl_url is specified in either the function or the client, a fallback neuroglancer deployment is used.

Parameters:

Name Type Description Default
state_id int

State id to retrieve

required
ngl_url str

Base url of a neuroglancer deployment. If None, defaults to the value for the datastack or the client. As a fallback, a default deployment is used.

None
target_site seunglab or cave - explorer or mainline or None

Set this to 'seunglab' for a seunglab deployment, or either 'cave-explorer'/'mainline' for a google main branch deployment. If None, checks the info field of the neuroglancer endpoint to determine which to use. Default is None.

None
static_url bool

If True, treats "state_id" as a static URL directly to the JSON and does not use the state service.

False
format_properties bool

If True, formats the url as a segment_properties info file

False

Returns:

Type Description
str

The full URL requested

get_neuroglancer_info(ngl_url=None)

Get the info field from a Neuroglancer deployment

Parameters:

Name Type Description Default
ngl_url str(optional)

URL to a Neuroglancer deployment. If None, defaults to the value for the datastack or the client.

None

Returns:

Type Description
dict

JSON-formatted info field from the Neuroglancer deployment

get_property_json(state_id)

Download a Neuroglancer JSON state

Parameters:

Name Type Description Default
state_id int

ID of a JSON state uploaded to the state service.

required

Returns:

Type Description
dict

JSON specifying a Neuroglancer state.

get_state_json(state_id)

Download a Neuroglancer JSON state

Parameters:

Name Type Description Default
state_id int

ID of a JSON state uploaded to the state service.

required

Returns:

Type Description
dict

JSON specifying a Neuroglancer state.

raise_for_status(r, log_warning=True) staticmethod

Raises requests.HTTPError, if one occurred.

save_state_json_local(json_state, filename, overwrite=False)

Save a Neuroglancer JSON state to a JSON file locally.

Parameters:

Name Type Description Default
json_state dict

Dict representation of a neuroglancer state

required
filename str

Filename to save the state to

required
overwrite bool

Whether to overwrite the file if it exists. Default False.

False

Returns:

Type Description
None

upload_property_json(property_json, state_id=None, max_size=2500000)

Upload a Neuroglancer JSON state

Parameters:

Name Type Description Default
propery_json dict

Dict representation of a neuroglancer segment properties json

required
state_id int

ID of a JSON state uploaded to the state service. Using a state_id is an admin feature.

None
max_size Optional[int]

Maximum size in bytes for the data to upload. Default is 2.5MB. Set to None for no limit.

2500000

Returns:

Type Description
int

state_id of the uploaded JSON state

upload_state_json(json_state, state_id=None, timestamp=None)

Upload a Neuroglancer JSON state

Parameters:

Name Type Description Default
json_state dict

Dict representation of a neuroglancer state

required
state_id int

ID of a JSON state uploaded to the state service. Using a state_id is an admin feature.

None
timestamp

Timestamp for json state date. Requires state_id.

None

Returns:

Type Description
int

state_id of the uploaded JSON state

JSONService(server_address=None, auth_client=None, api_version='latest', ngl_url=None, max_retries=None, pool_maxsize=None, pool_block=None, over_client=None)

Client factory to interface with the JSON state service.

Parameters:

Name Type Description Default
server_address str

URL to the JSON state server. If None, set to the default global server address. By default None.

None
auth_client An Auth client

An auth client with a token for the same global server, by default None

None
api_version int or latest

Which endpoint API version to use or 'latest'. By default, 'latest' tries to ask the server for which versions are available, if such functionality exists, or if not it defaults to the latest version for which there is a client. By default 'latest'

'latest'
ngl_url str or None

Default neuroglancer deployment URL. Only used for V1 and later.

None

neuroglancer_json_encoder(obj)

JSON encoder for neuroglancer states. Differs from normal in that it expresses ints as strings