nyx_client

NYC client SDK.

Submodules

Classes

NyxClient

A client for interacting with the Nyx system.

BaseNyxConfig

Configuration for the Nyx client.

ConfigType

Nyx configuration types.

NyxConfigExtended

Extended configuration for Nyx client with API integration.

Data

Represents the data in the Nyx system.

Package Contents

class nyx_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, genre, categories, content_type, lang='en', status='published', preview='', size=None, price=None, license_url=None, download_url=None, file=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 | None) – Approximate size of the data, if a file is provided the size will be calculated

  • 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 | None) – The URL where the data can be downloaded.

  • file (io.RawIOBase | None) – the file like object (RawIOBase) that you wish to upload

  • 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.

  • ValueError – When download_url and file are both provided or both missing

Return type:

nyx_client.data.Data

update_data(name, title, description, genre, categories, content_type, lang='en', status='published', preview='', size=None, price=None, license_url=None, download_url=None, file=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 | None) – 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 | None) – The URL where the data can be downloaded.

  • file (io.RawIOBase | None) – the file like object (RawIOBase) that you wish to upload

  • 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.

  • ValueError – When download_url and file are both provided or both missing

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.

class nyx_client.BaseNyxConfig

Configuration for the Nyx client.

nyx_url

The URL of the Nyx instance.

nyx_username

The username of the Nyx user.

nyx_email

The email of the Nyx user.

nyx_password

The password of the Nyx user.

classmethod from_env(env_file=None, override_token=None)

Create a BaseNyxConfig instance from environment variables.

Parameters:
  • env_file (str | None) – Path to the environment file.

  • override_token (str | None) – Token to override the default authentication.

Returns:

A new BaseNyxConfig instance.

Raises:

OSError – If required environment variables are not set.

__str__()

Return a string representation of the configuration.

Returns:

A JSON string of the configuration.

property nyx_auth: dict

Get the authentication credentials.

Returns:

A dictionary containing email and password for authentication.

Return type:

dict

class nyx_client.ConfigType

Bases: str, enum.Enum

Nyx configuration types.

class nyx_client.NyxConfigExtended

Extended configuration for Nyx client with API integration.

api_key

The API key for the selected provider.

provider

The type of configuration provider.

base_config

The base Nyx configuration.

classmethod from_env(provider, env_file=None, override_token=None)

Create a NyxConfigExtended instance from environment variables.

Parameters:
  • provider (ConfigType) – The type of configuration provider.

  • env_file (str | None) – Path to the environment file.

  • override_token (str | None) – Token to override the default authentication.

Returns:

A new NyxConfigExtended instance.

Raises:

Exception – If an unsupported config type is provided.

class nyx_client.Data(name, title, description, org, url, content_type, creator, categories, genre, size=0)

Represents the data in the Nyx system.

This class encapsulates the information and functionality related to the data in the Nyx system, including its metadata and content retrieval.

Parameters:
__str__()

Return a string representation of the Data instance.

as_string()

Download the content of the data as a string.

This method attempts to download the content from the data’s URL.

Returns:

The downloaded content as decoded text or None, if the download fails.

Return type:

str | None

as_bytes()

Download the content of the data as bytes.

This method attempts to download the content from the data’s URL.

Returns:

The downloaded content as bytes or None, if the download fails.

Return type:

bytes | None