nyx_client

NYC client SDK.

Submodules

Classes

Circle

Represents a circle, which is a grouping of remote hosts.

RemoteHost

Represents a remote host on the network.

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

Represents a circle, which is a grouping of remote hosts.

name: str

The name of the circle, this must be unique within your instance.

description: str | None = None

Optional description of what the circle is.

did: str | None = None

The did of the circle.

organizations: Sequence[RemoteHost] = ()

Optional list of remote organizations in the circle.

classmethod from_dict(value)

Builds a circle object from json.

Parameters:

value (dict) – a dictionary of the circle object

Returns:

Circle object

Return type:

Circle

as_dict()

Returns the object as a dictionary.

Returns:

A dictionary of the circle, that matches POST/PUT requests in the API.

Return type:

dict[str, Any]

class nyx_client.RemoteHost

Represents a remote host on the network.

did: str

the name of the organization

name: str = ''

the name of the organization

classmethod from_dict(value)

Builds a Remote Host object from json.

Parameters:

value (dict) – a dictionary of the organization object

Returns:

RemoteHost object

Return type:

RemoteHost

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: nyx_client.configuration.BaseNyxConfig

Configuration for the Nyx client.

org: str

Your organization name on Nyx.

name: str

Your Nyx Username.

community_mode: bool

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(text, *, categories=(), genre=None, creator=None, license=None, content_type=None, subscription_state='all', timeout=3, local_only=False)

Find products using text in the Nyx network (or local instance).

Usage of this endpoint is discouraged. Use get_data() instead, unless you want to perform a text search.

Parameters:
  • text (str) – Text to search for.

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

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

Find products in the Nyx network (or local instance).

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, access_control=None, circles=(), custom_metadata=(), connection_id=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.

  • access_control (Literal['all', 'none'] | None) – Either allow all, or allow none

  • circles (collections.abc.Sequence[nyx_client.circles.Circle]) – A list of circles to add share the data with

  • custom_metadata (collections.abc.Sequence[nyx_client.property.Property]) – Additional metadata properties to decorate the data with. Note that nyx-internal properties are not allowed.

  • connection_id (str | None) – the id of a connection to use (id from :class`.Connection`)

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, access_control=None, circles=(), custom_metadata=(), connection_id=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) – 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.

  • access_control (Literal['all', 'none'] | None) – Either allow all, or allow none

  • circles (collections.abc.Sequence[nyx_client.circles.Circle]) – A list of circles to add share the data with

  • custom_metadata (collections.abc.Sequence[nyx_client.property.Property]) – Additional metadata properties to decorate the data with. Note that nyx-internal properties are not allowed.

  • connection_id (str | None) – the id of a connection to use

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.

organizations()

Get a list of all organizations in the federated network.

Returns:

A list of RemoteHost objects

Raises:

requests.HTTPError – if the API request fails.

Return type:

list[nyx_client.circles.RemoteHost]

get_circles()

Get a list of circles.

Returns:

A list of Circle objects

Raises:

requests.HTTPError – if the API request fails.

Return type:

list[nyx_client.circles.Circle]

get_circle_by_name(circle_name)

Get a list of circles.

Parameters:

circle_name (str) – The name of the circle to get.

Returns:

A Circle object

Raises:

requests.HTTPError – if the API request fails.

Return type:

nyx_client.circles.Circle

create_circle(circle)

Create a circle.

Parameters:

circle (nyx_client.circles.Circle) – The circle to be created.

Returns:

An updated Circle object

Raises:

requests.HTTPError – If the API request fails.

Return type:

nyx_client.circles.Circle

update_circle(circle)

Updates a circle, based on the cirle’s name.

Parameters:

circle (nyx_client.circles.Circle) – The circle to be updated.

Raises:

requests.HTTPError – If the API request fails.

delete_circle_by_name(circle_name)

Deletes a circle.

Parameters:

circle_name (str) – The name of the circle to be deleted.

Raises:

requests.HTTPError – If the API request fails.

delete_circle(circle)

Deletes a circle.

Parameters:

circle (nyx_client.circles.Circle) – The circle to be deleted.

Raises:

requests.HTTPError – If the API request fails.

get_connections()

Lists all connections.

Returns:

A list of Connection objects

Raises:

requests.HTTPError – if the API request fails.

Return type:

list[nyx_client.connection.Connection]

class nyx_client.BaseNyxConfig

Configuration for the Nyx client.

nyx_url: str

The URL of the Nyx instance.

nyx_password: str

The email of the Nyx user.

nyx_email: str

The password of the Nyx user.

override_token: str | None = None

Allows injection of JWT token

classmethod from_env(env_file='.env', override_token=None)

Create a BaseNyxConfig instance from environment variables.

Parameters:
  • env_file (str) – Relative (to the working directory) or absolute path to the environment file.

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

Returns:

A new BaseNyxConfig instance.

Raises:

ValueError – If a required variable is not set in the env file or the file does not exist.

__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: str

The API key for the selected provider.

provider: ConfigType

The type of configuration provider.

base_config: BaseNyxConfig

The base Nyx configuration.

classmethod from_env(provider, env_file='.env', override_token=None)

Create a NyxConfigExtended instance from environment variables.

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

  • env_file (str) – Relative (to the working directory) or absolute path to the environment file.

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

Returns:

A new NyxConfigExtended instance.

Raises:

ValueError – If a required variable is not set in the env file, the env file does not exist or the corresponding api_key env var is not set.

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

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:
name: str

Unique name of data.

title: str

Human readable title of data.

description: str

Short description of data.

org: str

Your organization name.

url: str

The access URL of the data.

content_type: str

Content type of the data, can be in format application/json, or URI.

creator: str

Org name that created the data.

categories: list[str]

The categories of the data.

genre: str

The genre of the data.

size: int

Size in bytes of the data.

custom_metadata: list[nyx_client.property.Property]

Additional metadata properties to decorate the data with. Note that nyx-internal properties are not allowed.

connection_id: str | None

class`.Connection`)

Type:

The ID of the connection (id from

__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