SSB Collector Client

PyPI Status Python Version License

Documentation Tests Coverage Quality Gate Status

pre-commit Black Ruff Poetry

Features

  • Start new data collector tasks with custom specifications

  • List all running collector tasks

  • Stop running collector tasks by ID

  • Built-in authentication using Dapla Auth Client

  • Object-oriented API with CollectorClient class

Requirements

  • Python 3.10 or higher

  • Access to a Data Collector service

  • Dapla authentication credentials

Installation

You can install SSB Collector Client via pip from PyPI:

pip install ssb-collector-client

Usage

The SSB Collector Client provides an object-oriented interface using the CollectorClient class:

Quick Start

from ssb_collector_client import CollectorClient

# Initialize the client with your collector service URL
client = CollectorClient("https://your-collector-service.no/tasks")

# Define your collector specification
specification = {
    "type": "your-collector-type",
    # ... other specification parameters
}

# Start a new task
response = client.start(specification)

# Get all running tasks
tasks = client.running_tasks()
print(f"Running tasks: {tasks.json()}")

# Stop a specific task by ID
client.stop(task_id=1234)

Complete Example

Here’s a complete example using the CollectorClient class:

from ssb_collector_client import CollectorClient

# Initialize the client
collector_url = "https://your-collector-service.no/tasks"
client = CollectorClient(collector_url)

# Define your collector specification
specification = {
    "type": "example-type",
    "name": "my-collection-task",
    # ... other specification parameters
}

# Start a new task
print("Starting collector task...")
start_response = client.start(specification)
print(f"Task started: {start_response.status_code}")

# Check running tasks
print("\nChecking running tasks...")
tasks_response = client.running_tasks()
tasks = tasks_response.json()
print(f"Running tasks: {tasks}")

# Stop a specific task if needed
if tasks:
    task_id = 1234  # Replace with actual task ID
    print(f"\nStopping task {task_id}...")
    client.stop(task_id)

Please see the [Reference Guide] for details.

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license, SSB Collector Client is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project was generated from Statistics Norway’s SSB PyPI Template.