Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Solrstice is a solr client library written in rust. With this wrapper you can use it in python.
Both asyncio and blocking clients are provided. All apis have type hints.
pip install solrstice
import asyncio
from solrstice import SolrBasicAuth, SolrServerContext, SolrSingleServerHost, AsyncSolrCloudClient, UpdateQuery, \
SelectQuery, DeleteQuery
# A SolrServerContext specifies how the library should interact with Solr
context = SolrServerContext(SolrSingleServerHost('localhost:8983'), SolrBasicAuth('solr', 'SolrRocks'))
client = AsyncSolrCloudClient(context)
async def main():
# Create config and collection
await client.upload_config('example_config', 'path/to/config')
await client.create_collection('example_collection', 'example_config', shards=1, replication_factor=1)
# Index a document
await client.index(UpdateQuery(), 'example_collection', [{'id': 'example_document', 'title': 'Example document'}])
# Search for the document
response = await client.select(SelectQuery(fq=['title:Example document']), 'example_collection')
docs = response.get_docs_response().get_docs()
# Delete the document
await client.delete(DeleteQuery(ids=['example_document']), 'example_collection')
asyncio.run(main())
from solrstice import SolrBasicAuth, BlockingSolrCloudClient, SolrServerContext, SolrSingleServerHost, DeleteQuery, \
SelectQuery, UpdateQuery
# A SolrServerContext specifies how the library should interact with Solr
context = SolrServerContext(SolrSingleServerHost('localhost:8983'), SolrBasicAuth('solr', 'SolrRocks'))
client = BlockingSolrCloudClient(context)
# Create config and collection
client.upload_config('example_config', 'path/to/config')
client.create_collection('example_collection', 'example_config', shards=1, replication_factor=1)
# Index a document
client.index(UpdateQuery(), 'example_collection', [{'id': 'example_document', 'title': 'Example document'}])
# Search for the document
response = client.select(SelectQuery(fq=['title:Example document']), 'example_collection')
docs = response.get_docs_response().get_docs()
# Delete the document
client.delete(DeleteQuery(ids=['example_document']), 'example_collection')
from solrstice import GroupingComponent, SelectQuery, SolrServerContext, AsyncSolrCloudClient
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
group_builder = GroupingComponent(fields=["age"], limit=10)
select_builder = SelectQuery(fq=["age:[* TO *]"], grouping=group_builder)
groups = (await client.select(select_builder, "example_collection")).get_groups()
age_group = groups["age"]
docs = age_group.get_field_result()
from solrstice import GroupingComponent, SelectQuery, SolrServerContext, AsyncSolrCloudClient
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
group_builder = GroupingComponent(queries=["age:[0 TO 59]", "age:[60 TO *]"], limit=10)
select_builder = SelectQuery(fq=["age:[* TO *]"], grouping=group_builder)
groups = (await client.select(select_builder, "example_collection")).get_groups()
age_group = groups["age:[0 TO 59]"]
group = age_group.get_query_result()
docs = group.get_docs()
from solrstice import LuceneQuery, SelectQuery, SolrServerContext, AsyncSolrCloudClient
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
query_parser = LuceneQuery(df="population")
select_builder = SelectQuery(q="outdoors", def_type=query_parser)
response = (await client.select(select_builder, "example_collection")).get_docs_response()
assert response is not None
docs = response.get_docs()
from solrstice import DismaxQuery, SelectQuery, SolrServerContext, AsyncSolrCloudClient
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
query_parser = DismaxQuery(qf="interests^20", bq=["interests:cars^20"])
select_builder = SelectQuery(q="outdoors", def_type=query_parser)
response = (await client.select(select_builder, "example_collection")).get_docs_response()
assert response is not None
docs = response.get_docs()
from solrstice import EdismaxQuery, SelectQuery, SolrServerContext, AsyncSolrCloudClient
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
query_parser = EdismaxQuery(qf="interests^20", bq=["interests:cars^20"])
select_builder = SelectQuery(q="outdoors", def_type=query_parser)
response = (await client.select(select_builder, "example_collection")).get_docs_response()
assert response is not None
docs = response.get_docs()
from solrstice import FacetSetComponent, PivotFacetComponent, SelectQuery, SolrServerContext, AsyncSolrCloudClient
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
select_builder = SelectQuery(facet_set=FacetSetComponent(pivots=PivotFacetComponent(["interests,age"])))
response = await client.select(select_builder, "example_collection")
facets = response.get_facet_set()
pivots = facets.get_pivots()
interests_age = pivots.get("interests,age")
from solrstice import FacetSetComponent, FieldFacetComponent, FieldFacetEntry, SelectQuery, SolrServerContext, AsyncSolrCloudClient
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
facet_set = FacetSetComponent(fields=FieldFacetComponent(fields=[FieldFacetEntry("age")]))
select_builder = SelectQuery(facet_set=facet_set)
response = await client.select(select_builder, "example_collection")
facets = response.get_facet_set()
fields = facets.get_fields()
age = fields.get("age")
from solrstice import AsyncSolrCloudClient, SolrServerContext, SelectQuery, FacetSetComponent, FacetSetComponent
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
select_builder = SelectQuery(facet_set=FacetSetComponent(queries=["age:[0 TO 59]"]))
response = await client.select(select_builder, "example_collection")
facets = response.get_facet_set()
queries = facets.get_queries()
query = queries.get("age:[0 TO 59]")
from solrstice import JsonFacetComponent, JsonQueryFacet, SelectQuery, SolrServerContext, AsyncSolrCloudClient
async def main():
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
select_builder = SelectQuery(
json_facet=JsonFacetComponent(
facets={"below_60": JsonQueryFacet("age:[0 TO 59]")}
)
)
response = await client.select(select_builder, "example_collection")
facets = response.get_json_facets()
below_60 = facets.get_nested_facets().get("below_60")
assert below_60.get_count() == 4
from solrstice import JsonFacetComponent, JsonStatFacet, SelectQuery, SolrServerContext, AsyncSolrCloudClient
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
select_builder = SelectQuery(
json_facet=JsonFacetComponent(
facets={"total_people": JsonStatFacet("sum(count)")}
)
)
response = await client.select(select_builder, "example_collection")
facets = response.get_json_facets()
total_people = facets.get_flat_facets().get("total_people")
assert total_people == 1000
from solrstice import AsyncSolrCloudClient, SolrServerContext, SelectQuery, JsonFacetComponent, JsonTermsFacet
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
select_builder = SelectQuery(
json_facet=JsonFacetComponent(facets={"age": JsonTermsFacet("age")})
)
response = await client.select(select_builder, "example_collection")
facets = response.get_json_facets()
age_buckets = facets.get_nested_facets().get("age").get_buckets()
assert len(age_buckets) == 3
from solrstice import AsyncSolrCloudClient, SolrServerContext, SelectQuery, JsonFacetComponent, JsonQueryFacet, JsonStatFacet
client = AsyncSolrCloudClient(SolrServerContext('localhost:8983'))
async def main():
select_builder = SelectQuery(
json_facet=JsonFacetComponent(
facets={
"below_60": JsonQueryFacet(
"age:[0 TO 59]",
facets={"total_people": JsonStatFacet("sum(count)")},
)
}
)
)
response = await client.select(select_builder, "example_collection")
facets = response.get_json_facets()
total_people = (
facets.get_nested_facets()
.get("below_60")
.get_flat_facets()
.get("total_people")
)
assert total_people == 750.0
from solrstice import SolrServerContext, SolrSingleServerHost, SolrBasicAuth, AsyncSolrCloudClient
context = SolrServerContext(SolrSingleServerHost('localhost:8983'), SolrBasicAuth('solr', 'SolrRocks'))
client = AsyncSolrCloudClient(context)
from solrstice import SolrServerContext, SolrMultipleServerHost, SolrBasicAuth, AsyncSolrCloudClient
# The client will randomly select a server to send requests to. It will wait 5 seconds for a response, before trying another server.
context = SolrServerContext(
SolrMultipleServerHost(["localhost:8983", "localhost:8984"], 5),
SolrBasicAuth('solr', 'SolrRocks'),
)
client = AsyncSolrCloudClient(context)
from solrstice import SolrServerContext, ZookeeperEnsembleHostConnector, SolrBasicAuth, AsyncSolrCloudClient
async def main():
context = SolrServerContext(
await ZookeeperEnsembleHostConnector(["localhost:2181"], 30).connect(),
SolrBasicAuth('solr', 'SolrRocks'),
)
client = AsyncSolrCloudClient(context)
Multiprocessing does not work, and will block forever. Normal multithreading works fine.
Pyo3, the Rust library for creating bindings does not allow overriding the __init__
method on objects from
Rust. __new__
has to be overridden instead.
For example, if you want to create a simpler way to create a client
from typing import Optional
from solrstice import SolrServerContext, SolrSingleServerHost, SolrBasicAuth, AsyncSolrCloudClient, SolrAuth
class SolrClient(AsyncSolrCloudClient):
def __new__(cls, host: str, auth: Optional[SolrAuth] = None):
context = SolrServerContext(SolrSingleServerHost(host), auth)
return super().__new__(cls, context=context)
client = SolrClient("localhost:8983", SolrBasicAuth("username", "password"))
FAQs
A Solr client library written in Rust
We found that solrstice demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.