Skip to content

Commit 76d84cc

Browse files
committed
Docs: Add async examples and update sync examples
1 parent 0ec6884 commit 76d84cc

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

example/example_async_client.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Example usage of the async LeakIX client."""
2+
3+
import asyncio
4+
5+
import decouple
6+
7+
from leakix import AsyncClient, Scope
8+
9+
10+
API_KEY = decouple.config("API_KEY")
11+
12+
13+
async def example_search_services():
14+
"""Search for services using a raw query string."""
15+
async with AsyncClient(api_key=API_KEY) as client:
16+
response = await client.search("+country:FR +port:22", scope=Scope.SERVICE)
17+
assert response.status_code() == 200
18+
for event in response.json():
19+
print(f"{event.ip}:{event.port} - {event.summary}")
20+
21+
22+
async def example_search_leaks():
23+
"""Search for leaks using a raw query string."""
24+
async with AsyncClient(api_key=API_KEY) as client:
25+
response = await client.search("+plugin:GitConfigHttpPlugin", scope=Scope.LEAK)
26+
assert response.status_code() == 200
27+
for event in response.json():
28+
print(f"{event.host} - {event.summary}")
29+
30+
31+
async def main():
32+
await example_search_services()
33+
await example_search_leaks()
34+
35+
36+
if __name__ == "__main__":
37+
asyncio.run(main())

example/example_client.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import decouple
44

5-
from leakix import Client
5+
from leakix import Client, Scope
66
from leakix.field import CountryField, Operator, PluginField, TimeField
77
from leakix.plugin import Plugin
88
from leakix.query import MustNotQuery, MustQuery, RawQuery
@@ -118,6 +118,36 @@ def example_get_subdomains():
118118
print(response.json())
119119

120120

121+
def example_search_simple():
122+
"""Simple search using query string syntax (same as the website)."""
123+
response = CLIENT.search("+plugin:GitConfigHttpPlugin", scope=Scope.LEAK)
124+
for event in response.json():
125+
print(event.ip)
126+
127+
128+
def example_search_service():
129+
"""Search for services with multiple filters."""
130+
response = CLIENT.search("+country:FR +port:22", scope=Scope.SERVICE)
131+
for event in response.json():
132+
print(event.ip, event.port)
133+
134+
135+
def example_get_domain():
136+
"""Get services and leaks for a domain."""
137+
response = CLIENT.get_domain("example.com")
138+
if response.is_success():
139+
print("Services:", response.json()["services"])
140+
print("Leaks:", response.json()["leaks"])
141+
142+
143+
def example_bulk_export_stream():
144+
"""Streaming bulk export - memory efficient for large datasets."""
145+
query = MustQuery(field=PluginField(Plugin.GitConfigHttpPlugin))
146+
for aggregation in CLIENT.bulk_export_stream(queries=[query]):
147+
for event in aggregation.events:
148+
print(event.ip)
149+
150+
121151
if __name__ == "__main__":
122152
example_get_host_filter_plugin()
123153
example_get_service_filter_plugin()
@@ -131,3 +161,7 @@ def example_get_subdomains():
131161
example_bulk_service()
132162
example_bulk_export_last_event()
133163
example_get_subdomains()
164+
example_search_simple()
165+
example_search_service()
166+
example_get_domain()
167+
example_bulk_export_stream()

0 commit comments

Comments
 (0)