datalegion-cli 1.7.1__tar.gz → 1.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/PKG-INFO +8 -1
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/README.md +7 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/pyproject.toml +1 -1
- datalegion_cli-1.8.0/src/datalegion_cli/commands/__init__.py +26 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/commands/company.py +12 -2
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/commands/person.py +12 -2
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/test_commands.py +30 -0
- datalegion_cli-1.7.1/src/datalegion_cli/commands/__init__.py +0 -1
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/.gitignore +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/LICENSE +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/__init__.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/async_typer.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/client.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/commands/credits.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/commands/utility.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/config.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/logging.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/login.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/main.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/output.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/src/datalegion_cli/update.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/__init__.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/conftest.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/test_client.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/test_config.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/test_live.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/test_logging.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/test_login.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/test_output.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/test_package_contents.py +0 -0
- {datalegion_cli-1.7.1 → datalegion_cli-1.8.0}/tests/test_update.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: datalegion-cli
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.0
|
|
4
4
|
Summary: CLI for the Data Legion API — agent-friendly, fully async
|
|
5
5
|
Project-URL: Homepage, https://www.datalegion.ai
|
|
6
6
|
Project-URL: Documentation, https://www.datalegion.ai/docs
|
|
@@ -179,6 +179,13 @@ datalegion-cli person enrich --email john@example.com --fields "full_name,emails
|
|
|
179
179
|
datalegion-cli person search "SELECT * FROM people WHERE company_name ILIKE '%google%' AND state = 'CA'" --limit 5
|
|
180
180
|
```
|
|
181
181
|
|
|
182
|
+
`query` can also be an Elasticsearch-style query object as JSON (`bool`, `term`, `terms`, `match`, `match_phrase`, `range`, `exists`, `prefix`, `wildcard`, `nested`), on the response's own field names. For deep paging, pass each page's `next_cursor` back with `--cursor`; the last page has none. Company search takes both too.
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
datalegion-cli person search '{"bool": {"filter": [{"term": {"company_name": "google"}}, {"match": {"job_title": "engineer"}}]}}' --limit 100
|
|
186
|
+
datalegion-cli person search "SELECT * FROM people WHERE state = 'ohio'" --limit 100 --cursor "<next_cursor from the last page>"
|
|
187
|
+
```
|
|
188
|
+
|
|
182
189
|
### Person Discovery (Beta)
|
|
183
190
|
|
|
184
191
|
```bash
|
|
@@ -144,6 +144,13 @@ datalegion-cli person enrich --email john@example.com --fields "full_name,emails
|
|
|
144
144
|
datalegion-cli person search "SELECT * FROM people WHERE company_name ILIKE '%google%' AND state = 'CA'" --limit 5
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
+
`query` can also be an Elasticsearch-style query object as JSON (`bool`, `term`, `terms`, `match`, `match_phrase`, `range`, `exists`, `prefix`, `wildcard`, `nested`), on the response's own field names. For deep paging, pass each page's `next_cursor` back with `--cursor`; the last page has none. Company search takes both too.
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
datalegion-cli person search '{"bool": {"filter": [{"term": {"company_name": "google"}}, {"match": {"job_title": "engineer"}}]}}' --limit 100
|
|
151
|
+
datalegion-cli person search "SELECT * FROM people WHERE state = 'ohio'" --limit 100 --cursor "<next_cursor from the last page>"
|
|
152
|
+
```
|
|
153
|
+
|
|
147
154
|
### Person Discovery (Beta)
|
|
148
155
|
|
|
149
156
|
```bash
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""CLI command modules."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Annotated, Any
|
|
7
|
+
|
|
8
|
+
import typer
|
|
9
|
+
|
|
10
|
+
CursorOpt = Annotated[
|
|
11
|
+
str | None,
|
|
12
|
+
typer.Option(
|
|
13
|
+
"--cursor",
|
|
14
|
+
help="The previous page's next_cursor, for deep paging (instead of an offset).",
|
|
15
|
+
),
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def search_query(text: str) -> str | dict[str, Any]:
|
|
20
|
+
"""SQL as given, or a query object when the argument is a JSON object."""
|
|
21
|
+
if not text.lstrip().startswith("{"):
|
|
22
|
+
return text
|
|
23
|
+
try:
|
|
24
|
+
return json.loads(text)
|
|
25
|
+
except json.JSONDecodeError as e:
|
|
26
|
+
raise typer.BadParameter(f"The query looks like JSON but doesn't parse: {e.msg}.") from e
|
|
@@ -10,6 +10,7 @@ import typer
|
|
|
10
10
|
|
|
11
11
|
from datalegion_cli.async_typer import async_command
|
|
12
12
|
from datalegion_cli.client import APIError, LegionClient
|
|
13
|
+
from datalegion_cli.commands import CursorOpt, search_query
|
|
13
14
|
from datalegion_cli.output import emit_credits, emit_error, emit_json, emit_search_warning
|
|
14
15
|
|
|
15
16
|
app = typer.Typer(name="company", help="Company enrichment, search, and discovery.")
|
|
@@ -102,8 +103,14 @@ async def enrich(
|
|
|
102
103
|
@app.command()
|
|
103
104
|
@async_command
|
|
104
105
|
async def search(
|
|
105
|
-
query: Annotated[
|
|
106
|
+
query: Annotated[
|
|
107
|
+
str,
|
|
108
|
+
typer.Argument(
|
|
109
|
+
help="SQL SELECT query against the companies table, or a query object as JSON."
|
|
110
|
+
),
|
|
111
|
+
],
|
|
106
112
|
limit: LimitOpt = 1,
|
|
113
|
+
cursor: CursorOpt = None,
|
|
107
114
|
titlecase: TitleOpt = False,
|
|
108
115
|
include_fields: FieldsInclude = None,
|
|
109
116
|
exclude_fields: FieldsExclude = None,
|
|
@@ -114,12 +121,15 @@ async def search(
|
|
|
114
121
|
datalegion-cli company search "SELECT * FROM companies WHERE industry ILIKE '%software%' AND legion_employee_count > 100"
|
|
115
122
|
datalegion-cli company search "SELECT * FROM companies WHERE name ILIKE '%tech%'" --limit 20
|
|
116
123
|
datalegion-cli company search "SELECT * FROM companies WHERE domain = 'stripe.com'" --fields "name,domain,industry"
|
|
124
|
+
datalegion-cli company search '{"term": {"domain": "stripe.com"}}'
|
|
125
|
+
datalegion-cli company search "SELECT * FROM companies WHERE industry = 'banking'" --limit 100 --cursor <next_cursor>
|
|
117
126
|
"""
|
|
118
127
|
client = LegionClient()
|
|
119
128
|
try:
|
|
120
129
|
result = await client.company_search(
|
|
121
|
-
query=query,
|
|
130
|
+
query=search_query(query),
|
|
122
131
|
limit=limit,
|
|
132
|
+
cursor=cursor,
|
|
123
133
|
titlecase=titlecase,
|
|
124
134
|
include_fields=include_fields,
|
|
125
135
|
exclude_fields=exclude_fields,
|
|
@@ -10,6 +10,7 @@ import typer
|
|
|
10
10
|
|
|
11
11
|
from datalegion_cli.async_typer import async_command
|
|
12
12
|
from datalegion_cli.client import APIError, LegionClient
|
|
13
|
+
from datalegion_cli.commands import CursorOpt, search_query
|
|
13
14
|
from datalegion_cli.output import emit_credits, emit_error, emit_json, emit_search_warning
|
|
14
15
|
|
|
15
16
|
app = typer.Typer(name="person", help="Person enrichment, search, and discovery.")
|
|
@@ -128,8 +129,14 @@ async def enrich(
|
|
|
128
129
|
@app.command()
|
|
129
130
|
@async_command
|
|
130
131
|
async def search(
|
|
131
|
-
query: Annotated[
|
|
132
|
+
query: Annotated[
|
|
133
|
+
str,
|
|
134
|
+
typer.Argument(
|
|
135
|
+
help="SQL SELECT query against the people table, or a query object as JSON."
|
|
136
|
+
),
|
|
137
|
+
],
|
|
132
138
|
limit: LimitOpt = 1,
|
|
139
|
+
cursor: CursorOpt = None,
|
|
133
140
|
titlecase: TitleOpt = False,
|
|
134
141
|
include_fields: FieldsInclude = None,
|
|
135
142
|
exclude_fields: FieldsExclude = None,
|
|
@@ -139,12 +146,15 @@ async def search(
|
|
|
139
146
|
Examples:
|
|
140
147
|
datalegion-cli person search "SELECT * FROM people WHERE job_title = 'ceo' AND company_name ILIKE '%acme%'"
|
|
141
148
|
datalegion-cli person search "SELECT * FROM people WHERE city = 'san francisco'" --limit 20
|
|
149
|
+
datalegion-cli person search '{"term": {"company_name": "acme"}}' --limit 100
|
|
150
|
+
datalegion-cli person search "SELECT * FROM people WHERE state = 'ohio'" --limit 100 --cursor <next_cursor>
|
|
142
151
|
"""
|
|
143
152
|
client = LegionClient()
|
|
144
153
|
try:
|
|
145
154
|
result = await client.person_search(
|
|
146
|
-
query=query,
|
|
155
|
+
query=search_query(query),
|
|
147
156
|
limit=limit,
|
|
157
|
+
cursor=cursor,
|
|
148
158
|
titlecase=titlecase,
|
|
149
159
|
include_fields=include_fields,
|
|
150
160
|
exclude_fields=exclude_fields,
|
|
@@ -168,6 +168,36 @@ class TestPersonSearch:
|
|
|
168
168
|
assert result.exit_code == 0
|
|
169
169
|
|
|
170
170
|
|
|
171
|
+
class TestSearchQueryObjectAndCursor:
|
|
172
|
+
@pytest.mark.parametrize("entity", ["person", "company"])
|
|
173
|
+
def test_a_json_query_goes_as_an_object_with_the_cursor(self, monkeypatch, entity):
|
|
174
|
+
_mock_config(monkeypatch)
|
|
175
|
+
sent = []
|
|
176
|
+
|
|
177
|
+
async def fake_request(self, method, endpoint, *, payload=None, params=None):
|
|
178
|
+
sent.append(payload)
|
|
179
|
+
return {"matches": [], "total": 0, "next_cursor": "abc"}
|
|
180
|
+
|
|
181
|
+
monkeypatch.setattr("datalegion_cli.client.LegionClient.request", fake_request)
|
|
182
|
+
result = runner.invoke(
|
|
183
|
+
app, [entity, "search", '{"exists": {"field": "legion_id"}}', "--cursor", "abc"]
|
|
184
|
+
)
|
|
185
|
+
assert result.exit_code == 0, result.output
|
|
186
|
+
assert sent[0]["query"] == {"exists": {"field": "legion_id"}}
|
|
187
|
+
assert sent[0]["cursor"] == "abc"
|
|
188
|
+
assert json.loads(result.stdout)["next_cursor"] == "abc"
|
|
189
|
+
|
|
190
|
+
def test_a_query_that_looks_like_json_but_does_not_parse_is_refused(self, monkeypatch):
|
|
191
|
+
_mock_config(monkeypatch)
|
|
192
|
+
result = runner.invoke(app, ["person", "search", "{not json"])
|
|
193
|
+
assert result.exit_code == 2
|
|
194
|
+
|
|
195
|
+
def test_sql_stays_a_string(self):
|
|
196
|
+
from datalegion_cli.commands import search_query
|
|
197
|
+
|
|
198
|
+
assert search_query("SELECT * FROM people") == "SELECT * FROM people"
|
|
199
|
+
|
|
200
|
+
|
|
171
201
|
class TestPersonDiscover:
|
|
172
202
|
def test_discover(self, monkeypatch):
|
|
173
203
|
_mock_config(monkeypatch)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"""CLI command modules."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|