Skip to main content

Python client library for complementing the sciDX library

Project description

scidx-tools

scidx-tools is a complementary Python library to scidx that provides additional functionalities for managing data and testing some functionalities in full. This library offers extended tools and utilities to enhance your experience in managing datasets and organizations.

Features

  • Send data to a Kafka topic
  • Retrieve data from a Kafka topic

Installation

To install the library, you can use pip:

pip install scidx_tools

For detailed installation instructions and dependencies, see installation.

Configuration

To configure the library, you need to set the API URL for your sciDX REST API instance. This can be done by initializing the sciDXToolsClient with the appropriate URL:

from scidx_tools.client import sciDXToolsClient

api_url = "http://your-api-url.com"
KAFKA_HOST = 'placeholder'
KAFKA_PORT = 'placeholder'
OWNER_ORG = "placeholder"
client = sciDXToolsClient(api_url)

For detailed configuration instructions, see Configuration.

Usage

Here is a quick example of how to use the library:

import asyncio
import random
import time
from scidx.client import sciDXClient
from scidx_tools.client import sciDXToolsClient

# Constants
API_URL = "http://localhost:8000"
KAFKA_HOST = 'placeholder'
KAFKA_PORT = 'placeholder'
OWNER_ORG = "placeholder"

# Initialize sciDXClient and sciDXToolsClient
client = sciDXClient(API_URL)
tools_client = sciDXToolsClient(API_URL)

# Generate a unique Kafka topic name and a producer
kafka_topic = tools_client.generate_unique_kafka_topic()
producer = tools_client.producer(KAFKA_HOST, KAFKA_PORT, kafka_topic)

# Send random messages to Kafka topic
asyncio.run(await producer.send_random_messages(num_messages=15))

# Register Kafka topic as dataset
dataset_data = {
    "dataset_name": kafka_topic,
    "dataset_title": "Random Topic Example",
    "owner_org": OWNER_ORG,
    "kafka_topic": kafka_topic,
    "kafka_host": KAFKA_HOST,
    "kafka_port": KAFKA_PORT,
    "dataset_description": "This is a randomly generated Kafka topic registered as a CKAN dataset."
}
client.register_kafka(**dataset_data)

# Add a delay to ensure the dataset is indexed
time.sleep(2)

# Retrieve Kafka dataset information from API
kafka_datasets = client.search_kafka(kafka_topic=kafka_topic, kafka_host=KAFKA_HOST, kafka_port=KAFKA_PORT)

# Ensure that at least one dataset is returned
assert len(kafka_datasets) > 0, "No Kafka datasets found"

dataset_info = next((ds for ds in kafka_datasets if ds['resources'][0]['kafka_topic'] == kafka_topic), None)
assert dataset_info is not None, f"Kafka topic {kafka_topic} not found in datasets"

# Show Kafka connection details
print(dataset_info['resources'][0])

# Consume messages from Kafka topic using retrieved information
print(f"Starting to consume messages from topic: {kafka_topic}")

messages = await tools_client.consume_kafka_messages(topic=kafka_topic, host=KAFKA_HOST, port=KAFKA_PORT)
assert len(messages) > 0, f"No messages received from topic {kafka_topic}"

For more usage examples and detailed explanations, see Usage.

Testing

To run the tests for this project, you can use pytest:

pytest

For detailed testing instructions, see Testing.

Contributing

We welcome contributions to the scidx-tools project. To contribute, please follow the guidelines in Contributing.

License

This project is licensed under the MIT License. See LICENSE.md for more details.

Contact

For any questions or suggestions, please open an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scidx_tools-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

scidx_tools-0.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file scidx_tools-0.1.0.tar.gz.

File metadata

  • Download URL: scidx_tools-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for scidx_tools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b27ba95f1e9e6313954ce9a6f365a04922284bfd3490062cd5e453c3570bc5c1
MD5 394d823b8a6359853b3d6daf2aa3a63f
BLAKE2b-256 bbcf4e44b3fb351d7849272d914174614a80759f12c6e3293378d51b9c63e8a7

See more details on using hashes here.

File details

Details for the file scidx_tools-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: scidx_tools-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for scidx_tools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b1ac4f0d337da8049eb6e8fed82d8c84b5bef5a8ebf19894ba1f409e92adc39
MD5 2dba7a1d9d75eb8b48a85bf0598189a6
BLAKE2b-256 85a81946c2272bffe7f8193ad0c5a698c6c6e7e390ac6aba10458e08e69399d6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page