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.
Metadata
Release files for scidx-tools 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scidx_tools-0.1.0.tar.gz | 10.9 kB | Without provenance | Details for scidx_tools-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scidx_tools-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for scidx_tools-0.1.0-py3-none-any.whl |
Total release size: 24.4 kB
Release files / scidx_tools-0.1.0.tar.gz
| Download URL | scidx_tools-0.1.0.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b27ba95f1e9e6313954ce9a6f365a04922284bfd3490062cd5e453c3570bc5c1
|
|
BLAKE2b-256 checksum How to use checksums |
bbcf4e44b3fb351d7849272d914174614a80759f12c6e3293378d51b9c63e8a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Release files / scidx_tools-0.1.0-py3-none-any.whl
| Download URL | scidx_tools-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b1ac4f0d337da8049eb6e8fed82d8c84b5bef5a8ebf19894ba1f409e92adc39
|
|
BLAKE2b-256 checksum How to use checksums |
85a81946c2272bffe7f8193ad0c5a698c6c6e7e390ac6aba10458e08e69399d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Security for scidx-tools 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.