Elastro
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
elastic-cli config init
# Create an index
elastic-cli index create products --shards 3 --replicas 1 --mapping ./product-mapping.json
# Add a document
elastic-cli doc index products --id 1 --file ./product.json
# Search documents
elastic-cli search products "name:laptop" --format json
Documentation
For more detailed documentation, please refer to the docs directory:
Examples
Check out the examples directory for more usage examples:
Contributing
We welcome contributions to Elastro! If you'd like to contribute, please follow these guidelines:
Development Setup
- Fork the repository
- Clone your fork:
git clone https://github.com/your-username/elastro.git - Install development dependencies:
pip install -e ".[dev]" - Create a branch for your changes:
git checkout -b feature/your-feature-name
Code Standards
- Follow PEP 8 style guidelines
- Use type hints for all method signatures and return values
- Write comprehensive docstrings (PEP 257) for all public classes and methods
- Keep files under 300 lines of code maximum
- Implement custom exception classes for different error categories
- Validate inputs using Pydantic before processing
Architecture Guidelines
- Maintain separation of concerns between core functionality and interfaces
- Design modular components with single responsibilities
- Follow SOLID principles
- Implement dependency injection for better testability
- Structure code by functionality rather than technology type
Testing
- Write unit tests with pytest for all new functionality
- Maintain test coverage of at least 80% for core functionality
- Run tests using
./run_tests.shbefore submitting a PR
Submitting Changes
- Ensure your code follows the project's standards
- Write meaningful commit messages
- Push your changes to your fork
- Submit a pull request to the main repository
- Describe your changes and the problem they solve
Documentation
- Update documentation for any changed functionality
- Add examples for new features
- Write clear, concise docstrings for all public APIs
License
MIT
Metadata
Release files for elastro 0.1.5
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 |
|---|---|---|---|---|
| elastro-0.1.5.tar.gz | 89.0 kB | Without provenance | Details for elastro-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| elastro-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for elastro-0.1.5-py3-none-any.whl |
Total release size: 130.8 kB
Release files / elastro-0.1.5.tar.gz
| Download URL | elastro-0.1.5.tar.gz |
|---|---|
| Size | 89.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a1efcccf51482945a4c645e37f40d8880a8490ba10c140cc643f3fb891a10de
|
|
BLAKE2b-256 checksum How to use checksums |
c47dd78fcc7494535bc18ca13a148b5480837a2dc5586c5620f373284f95c607
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / elastro-0.1.5-py3-none-any.whl
| Download URL | elastro-0.1.5-py3-none-any.whl |
|---|---|
| Size | 41.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91474598c5c96f2b7c77e6efe4b24e9a694d19e07934f058e81eb4682e505fc4
|
|
BLAKE2b-256 checksum How to use checksums |
8024230e786798ae3d3b68e2b7d7a54593fa4a646f7094d541204f3641fa4f81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Security for elastro 0.1.5
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.