nyx_client.client

Module for managing connection to Nyx.

Classes

SparqlResultType

Available query result (response) types for SPARQL query.

NyxClient

A client for interacting with the Nyx system.

Module Contents

class nyx_client.client.SparqlResultType

Bases: str, enum.Enum

Available query result (response) types for SPARQL query.

__str__()

Return str(self).

Return type:

str

class nyx_client.client.NyxClient(config=None)

A client for interacting with the Nyx system.

This client provides methods for querying and processing data from Nyx.

Parameters:

config (nyx_client.configuration.BaseNyxConfig | None)

config

Configuration for the Nyx client.

org

Your organization name on Nyx.

name

Your Nyx Username.

community_mode

If you’re using community mode.

sparql_query(query, result_type=SparqlResultType.SPARQL_JSON, local_only=False)

Execute a SPARQL query and process the results.

NOTE: This method is experimental and its definition might change without notice!

Parameters:
  • query (str) – A SPARQL 1.1 query string.

  • result_type (SparqlResultType) – The result format for the query.

  • local_only (bool) – Whether to only query the local Nyx instance as opposed to the whole Nyx network.

Returns:

A string of the result in the specified format

Raises:

requests.HTTPError – If there’s an HTTP error during the query execution.

Return type:

str

categories()

Retrieve all categories from the federated network.

Returns:

A list of category names.

Return type:

list[str]

genres()

Retrieve all genres from the federated network.

Returns:

A list of genre names.

Return type:

list[str]

creators()

Retrieve all creators from the federated network.

Returns:

A list of creator names.

Return type:

list[str]

content_types()

Retrieve all content Types from the federated network.

Returns:

A list of content types.

Return type:

list[str]

licenses()

Retrieve all licenses from the federated network.

Returns:

A list of licenses.

Return type:

list[str]

search(*, categories=(), genre=None, creator=None, text=None, license=None, content_type=None, subscription_state='all', timeout=3, local_only=False)

Search for new data in the Nyx system.

Parameters:
  • categories (collections.abc.Sequence[str]) – Sequence of categories to filter by.

  • genre (str | None) – Genre to filter by.

  • creator (str | None) – Creator to filter by.

  • text (str | None) – Text to search for.

  • license (str | None) – License to filter by.

  • content_type (str | None) – Content type to filter by.

  • subscription_state (Literal['subscribed', 'all', 'not-subscribed']) – Subscription state to filter by.

  • timeout (int) – Timeout for the search request in seconds.

  • local_only (bool) – Whether to only search for data defined in the local Nyx instance as opposed to the whole Nyx network.

Returns:

A list of Data instances matching the search criteria.

Return type:

list[nyx_client.data.Data]

my_subscriptions(*, categories=(), genre=None, creator=None, license=None, content_type=None)

Retrieve only subscribed data from the federated network.

Parameters:
  • categories (collections.abc.Sequence[str]) – Sequence of categories to filter by.

  • genre (str | None) – Genre to filter by.

  • creator (str | None) – Creator to filter by.

  • license (str | None) – License to filter by.

  • content_type (str | None) – Content type to filter by.

Returns:

A list of Data instances matching the criteria.

Return type:

list[nyx_client.data.Data]

my_data(categories=(), genre=None, license=None, content_type=None)

Retrieve data I have created.

Parameters:
  • categories (collections.abc.Sequence[str]) – Sequence of categories to filter by.

  • genre (str | None) – Genre to filter by.

  • license (str | None) – License to filter by.

  • content_type (str | None) – Content type to filter by.

Returns:

A list of Data instances matching the criteria.

Return type:

list[nyx_client.data.Data]

get_data(*, categories=(), genre=None, creator=None, license=None, content_type=None, subscription_state='all', local_only=False)

Retrieve data from the federated network.

Parameters:
  • categories (collections.abc.Sequence[str]) – Sequence of categories to filter by.

  • genre (str | None) – Genre to filter by.

  • creator (str | None) – Creator to filter by.

  • license (str | None) – License to filter by.

  • content_type (str | None) – Content type to filter by.

  • subscription_state (Literal['subscribed', 'all', 'not-subscribed']) – Subscription state to filter by.

  • local_only (bool) – Whether to only interrogate data defined in the local Nyx instance as opposed to the whole Nyx network.

Returns:

A list of Data instances matching the criteria.

Return type:

list[nyx_client.data.Data]

get_my_data_by_name(name)

Retrieve your own data based on its unique name.

This only works on data you own

Parameters:

name (str) – The data unique name (unique per organization).

Returns:

Your Data instance identified with the provided name.

Raises:

requests.HTTPError – If the API request fails.

Return type:

nyx_client.data.Data

create_data(name, title, description, size, genre, categories, download_url, content_type, lang='en', status='published', preview='', price=None, license_url=None)

Create new data in the system.

Parameters:
  • name (str) – The unique identifier for the data.

  • title (str) – The display title of the data.

  • description (str) – A detailed description of the data.

  • size (int) – The size of the data, typically in bytes.

  • genre (str) – The genre or category of the data.

  • categories (collections.abc.Sequence[str]) – A list of categories the data belongs to.

  • download_url (str) – The URL where the data can be downloaded.

  • content_type (str) – The mime type of the data located at download_url.

  • lang (str) – The language of the data.

  • status (str) – The publication status of the data.

  • preview (str) – A preview or sample of the data.

  • price (int | None) – The price of the data in cents. If 0, the data is free.

  • license_url (str | None) – The URL of the license for the data.

Returns:

A Data instance, containing the download URL and title.

Raises:

requests.HTTPError – If the API request fails.

Return type:

nyx_client.data.Data

update_data(name, title, description, size, genre, categories, download_url, content_type, lang='en', status='published', preview='', price=None, license_url=None)

Updates existing data in the system.

Parameters:
  • name (str) – The unique identifier for the data.

  • title (str) – The display title of the data.

  • description (str) – A detailed description of the data.

  • size (int) – The size of the data, typically in bytes.

  • genre (str) – The genre or category of the data.

  • categories (collections.abc.Sequence[str]) – A list of categories the data belongs to.

  • download_url (str) – The URL where the data can be downloaded.

  • content_type (str) – The mime type of the data located at download_url.

  • lang (str) – The language of the data.

  • status (str) – The publication status of the data.

  • preview (str) – A preview or sample of the data.

  • price (int | None) – The price of the data in cents. If 0, the data is free.

  • license_url (str | None) – The URL of the license for the data.

Returns:

A Data instance, containing the updated information.

Raises:

requests.HTTPError – If the API request fails.

Return type:

nyx_client.data.Data

delete_data(data)

Delete the provided data from Nyx.

Parameters:

data (nyx_client.data.Data) – The data to delete.

Raises:

requests.HTTPError – If the API request fails.

delete_data_by_name(name)

Delete the data uniquely identified by the provided name from Nyx.

Parameters:

name (str) – The data unique name.

Raises:

requests.HTTPError – If the API request fails.

subscribe(data)

Subscribe to the data.

Parameters:

data (nyx_client.data.Data) – The data object to subscribe to.

Raises:

requests.HTTPError – If the API request fails.

unsubscribe(data)

Unsubscribe from the data.

Parameters:

data (nyx_client.data.Data) – The data object to unsubscribe from.

Raises:

requests.HTTPError – If the API request fails.