nyx_client¶
NYC client SDK.
Submodules¶
Classes¶
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.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:
- 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(*, 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:
- 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)¶
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:
- 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)¶
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:
- 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:
- 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.
- __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.
- 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.