Skip to main content

A comprehensive Python library for Elasticsearch management with both programmatic and CLI interfaces

Project description

Elastro

      .   *   .       .   *   .      .
    .   _   .   *   .    *    .   *
  _ __| | __ _ ___| |_ _ __ ___    .
  / _ \ |/ _` / __| __| '__/ _ \  *
 |  __/ | (_| \__ \ |_| | | (_) |  .
  \___|_|\__,_|___/\__|_|  \___/ .
      .    *     .      *    .   *

License: MIT Python 3.8+ Code Style: Black

A comprehensive Python module for managing Elasticsearch operations within pipeline processes.

Overview

Elastro is a Python library designed to simplify interactions with Elasticsearch. It provides a clean, intuitive API for common Elasticsearch operations including:

  • Index management (create, update, delete)
  • Document operations (indexing, searching, updating)
  • Datastream management
  • Advanced query building and search functionality

The library offers both a programmatic API and a command-line interface for seamless integration with various workflows.

Installation

pip install elastro

Or from source:

git clone https://github.com/Fremen-Labs/elastro.git
cd elastro
pip install -e .

Basic Usage

Client Connection

from elastro import ElasticsearchClient

# Connect using API key
client = ElasticsearchClient(
    hosts=["https://elasticsearch:9200"],
    auth={"api_key": "your-api-key"}
)

# Or using basic auth
client = ElasticsearchClient(
    hosts=["https://elasticsearch:9200"],
    auth={"username": "elastic", "password": "password"}
)

# Connect to Elasticsearch
client.connect()

Index Management

from elastro import IndexManager

index_manager = IndexManager(client)

# Create an index
index_manager.create(
    name="products",
    settings={
        "number_of_shards": 3,
        "number_of_replicas": 1
    },
    mappings={
        "properties": {
            "name": {"type": "text"},
            "price": {"type": "float"},
            "description": {"type": "text"},
            "created": {"type": "date"}
        }
    }
)

# Check if an index exists
if index_manager.exists("products"):
    print("Products index exists!")
    
# Delete an index
index_manager.delete("products")

Document Operations

from elastro import DocumentManager

doc_manager = DocumentManager(client)

# Index a document
doc_manager.index(
    index="products",
    id="1",
    document={
        "name": "Laptop",
        "price": 999.99,
        "description": "High-performance laptop",
        "created": "2023-05-01T12:00:00"
    }
)

# Search for documents
results = doc_manager.search(
    index="products",
    query={"match": {"name": "laptop"}}
)

print(results)

CLI Usage

# Initialize configuration
elastro config init

# Create an index
elastro index create products --shards 3 --replicas 1

# Interactive Template Wizard
elastro template wizard

# Interactive ILM Policy Wizard
elastro ilm create my-policy

# List ILM Policies (Table View)
elastro ilm list

# Add a document
elastro doc index products --id 1 --file ./product.json

# Search documents
elastro doc search products --term category=laptop

ILM (Index Lifecycle Management)

Elastro provides a powerful CLI for managing ILM policies, including an interactive wizard.

# List all policies (Table View)
elastro ilm list

# List with full JSON details (limited to first 2)
elastro ilm list --full

# Create a policy using the Interactive Wizard (Recommended)
elastro ilm create my-policy
# Follow the prompts to configure Hot, Warm, Cold, and Delete phases.

# Create a policy from a file
elastro ilm create my-policy --file ./policy.json

# Explain lifecycle status for an index (includes step info for debugging)
elastro ilm explain my-index

Snapshot & Restore

Manage backup repositories and snapshots with ease.

Repositories:

# List all repositories
elastro snapshot repo list

# Create a filesystem repository
elastro snapshot repo create my_backup fs --setting location=/tmp/backups

# Create an S3 repository
elastro snapshot repo create my_s3_backup s3 --setting bucket=my-bucket --setting region=us-east-1

Snapshots:

# List snapshots in a repository
elastro snapshot list my_backup

# Create a snapshot (async default)
elastro snapshot create my_backup snapshot_1

# Create and wait for completion
elastro snapshot create my_backup snapshot_2 --wait --indices "logs-*,metrics-*"

# Restore a snapshot (Interactive Wizard)
elastro snapshot restore
# Launches a wizard to select repo -> snapshot -> indices -> rename pattern

# Restore specific indices from CLI
elastro snapshot restore my_backup snapshot_1 --indices "logs-*"

Examples

Check out the examples directory for more usage examples:

Contributing

We welcome contributions to Elastro! Please see CONTRIBUTING.md for guidelines on how to get started, code standards, and submission processes.

License

MIT

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

elastro_client-1.2.3.tar.gz (116.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

elastro_client-1.2.3-py3-none-any.whl (68.8 kB view details)

Uploaded Python 3

File details

Details for the file elastro_client-1.2.3.tar.gz.

File metadata

  • Download URL: elastro_client-1.2.3.tar.gz
  • Upload date:
  • Size: 116.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for elastro_client-1.2.3.tar.gz
Algorithm Hash digest
SHA256 15f5aab11bfbd54c79de71914d459002f0f2c30d2cefd2eef9b5a6ce95870f4b
MD5 a349dae8b6a89c3debfa70e90a3fb6b0
BLAKE2b-256 57a0eb55865c6757b8b6ad93090b6056e33cae1b1955155ae2a6d1081eed6b13

See more details on using hashes here.

File details

Details for the file elastro_client-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: elastro_client-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 68.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for elastro_client-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2671215914e502a36d26c3fcefeaf70826a69b634e69d3ec08f4991542f12245
MD5 770e3410cce118bcfa1bb95b42949856
BLAKE2b-256 cfeb8507d5c12626da4bf73f21a46048522f54c5d170a3b1e1dd02f17d6937ee

See more details on using hashes here.

Supported by

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