nyx_client¶
NYC client SDK.
Submodules¶
Classes¶
Represents a circle, which is a grouping of remote hosts. |
|
Represents a remote host on the network. |
|
A client for interacting with the Nyx system. |
|
Configuration for the Nyx client. |
|
Nyx configuration types. |
|
Extended configuration for Nyx client with API integration. |
|
Represents the data in the Nyx system. |
Package Contents¶
- class nyx_client.Circle¶
Represents a circle, which is a grouping of remote hosts.
- organizations: Sequence[RemoteHost] = ()¶
Optional list of remote organizations in the circle.
- classmethod from_dict(value)¶
Builds a circle object from json.
- class nyx_client.RemoteHost¶
Represents a remote host on the network.
- 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.
- 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:
- categories()¶
Retrieve all categories from the federated network.
- genres()¶
Retrieve all genres from the federated network.
- creators()¶
Retrieve all creators from the federated network.
- content_types()¶
Retrieve all content Types from the federated network.
- licenses()¶
Retrieve all licenses from the federated network.
- 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:
- my_subscriptions(*, categories=(), genre=None, creator=None, license=None, content_type=None)¶
Retrieve only subscribed data from the federated network.
- Parameters:
- Returns:
A list of Data instances matching the criteria.
- Return type:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- get_circles()¶
Get a list of circles.
- Returns:
A list of Circle objects
- Raises:
requests.HTTPError – if the API request fails.
- Return type:
- 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:
- 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:
- 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:
- class nyx_client.BaseNyxConfig¶
Configuration for the Nyx client.
- classmethod from_env(env_file='.env', override_token=None)¶
Create a BaseNyxConfig instance from environment variables.
- Parameters:
- 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.
- class nyx_client.NyxConfigExtended¶
Extended configuration for Nyx client with API integration.
- 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:
- custom_metadata: list[nyx_client.property.Property]¶
Additional metadata properties to decorate the data with. Note that nyx-internal properties are not allowed.
- __str__()¶
Return a string representation of the Data instance.