Skip to content

Commit 27feb33

Browse files
committed
Docs: Add async examples and update sync examples
1 parent 32fa143 commit 27feb33

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

example/example_async_client.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import asyncio
2+
3+
import decouple
4+
5+
from leakix import AsyncClient, Scope
6+
7+
API_KEY = decouple.config("API_KEY")
8+
9+
10+
async def example_search():
11+
"""Simple async search using query string syntax."""
12+
async with AsyncClient(api_key=API_KEY) as client:
13+
response = await client.search("+plugin:GitConfigHttpPlugin", scope=Scope.LEAK)
14+
if response.is_success():
15+
for event in response.json():
16+
print(event.ip, event.host)
17+
18+
19+
async def example_get_host():
20+
"""Async host lookup."""
21+
async with AsyncClient(api_key=API_KEY) as client:
22+
response = await client.get_host("8.8.8.8")
23+
if response.is_success():
24+
print("Services:", response.json()["services"])
25+
print("Leaks:", response.json()["leaks"])
26+
27+
28+
async def example_get_domain():
29+
"""Async domain lookup."""
30+
async with AsyncClient(api_key=API_KEY) as client:
31+
response = await client.get_domain("example.com")
32+
if response.is_success():
33+
print("Services:", response.json()["services"])
34+
print("Leaks:", response.json()["leaks"])
35+
36+
37+
if __name__ == "__main__":
38+
asyncio.run(example_search())

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)