datalegion-cli 1.3.0__tar.gz → 1.4.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.
Files changed (28) hide show
  1. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/PKG-INFO +4 -3
  2. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/README.md +2 -2
  3. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/pyproject.toml +2 -1
  4. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/commands/company.py +1 -10
  5. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/commands/person.py +1 -10
  6. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/config.py +1 -0
  7. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/login.py +10 -5
  8. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/main.py +9 -2
  9. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/tests/test_commands.py +28 -0
  10. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/tests/test_login.py +30 -6
  11. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/.gitignore +0 -0
  12. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/__init__.py +0 -0
  13. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/async_typer.py +0 -0
  14. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/client.py +0 -0
  15. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/commands/__init__.py +0 -0
  16. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/commands/credits.py +0 -0
  17. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/commands/utility.py +0 -0
  18. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/logging.py +0 -0
  19. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/output.py +0 -0
  20. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/src/datalegion_cli/update.py +0 -0
  21. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/tests/__init__.py +0 -0
  22. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/tests/conftest.py +0 -0
  23. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/tests/test_client.py +0 -0
  24. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/tests/test_config.py +0 -0
  25. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/tests/test_logging.py +0 -0
  26. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/tests/test_output.py +0 -0
  27. {datalegion_cli-1.3.0 → datalegion_cli-1.4.0}/tests/test_package_contents.py +0 -0
  28. {datalegion_cli-1.3.0 → datalegion_cli-1.4.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.0
3
+ Version: 1.4.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
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.11
18
18
  Classifier: Programming Language :: Python :: 3.12
19
19
  Classifier: Programming Language :: Python :: 3.13
20
20
  Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Programming Language :: Python :: 3.15
21
22
  Classifier: Typing :: Typed
22
23
  Requires-Python: >=3.11
23
24
  Requires-Dist: cryptography>=44.0.0
@@ -104,7 +105,7 @@ datalegion-cli login --team-id 7 # when your account has several teams
104
105
  datalegion-cli login --no-browser # headless: prints the link to open on another device
105
106
  ```
106
107
 
107
- The key belongs to this machine (named after its hostname, or `--device <name>`). Signing in again replaces it, and you can disconnect it from Connected Apps in the dashboard.
108
+ The key belongs to this machine, named with a random id (`cli-` plus 8 hex characters) that the CLI generates on first login and keeps in its config, so nothing about the machine (such as its hostname) is sent. Pass `--device <name>` for a readable label instead. Signing in again replaces it, and you can disconnect it from Connected Apps in the dashboard.
108
109
 
109
110
  Or set an API key yourself (stored encrypted on disk):
110
111
 
@@ -164,7 +165,7 @@ datalegion-cli person enrich --name "Jane Smith" --company "Acme Corp" --city "N
164
165
  datalegion-cli person enrich --social-url "https://linkedin.com/in/johndoe"
165
166
 
166
167
  # Multiple results with minimum confidence
167
- datalegion-cli person enrich --email john@example.com --multiple --min-confidence high
168
+ datalegion-cli person enrich --email john@example.com --min-confidence high
168
169
 
169
170
  # Select specific fields
170
171
  datalegion-cli person enrich --email john@example.com --fields "full_name,emails,phones"
@@ -70,7 +70,7 @@ datalegion-cli login --team-id 7 # when your account has several teams
70
70
  datalegion-cli login --no-browser # headless: prints the link to open on another device
71
71
  ```
72
72
 
73
- The key belongs to this machine (named after its hostname, or `--device <name>`). Signing in again replaces it, and you can disconnect it from Connected Apps in the dashboard.
73
+ The key belongs to this machine, named with a random id (`cli-` plus 8 hex characters) that the CLI generates on first login and keeps in its config, so nothing about the machine (such as its hostname) is sent. Pass `--device <name>` for a readable label instead. Signing in again replaces it, and you can disconnect it from Connected Apps in the dashboard.
74
74
 
75
75
  Or set an API key yourself (stored encrypted on disk):
76
76
 
@@ -130,7 +130,7 @@ datalegion-cli person enrich --name "Jane Smith" --company "Acme Corp" --city "N
130
130
  datalegion-cli person enrich --social-url "https://linkedin.com/in/johndoe"
131
131
 
132
132
  # Multiple results with minimum confidence
133
- datalegion-cli person enrich --email john@example.com --multiple --min-confidence high
133
+ datalegion-cli person enrich --email john@example.com --min-confidence high
134
134
 
135
135
  # Select specific fields
136
136
  datalegion-cli person enrich --email john@example.com --fields "full_name,emails,phones"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "datalegion-cli"
3
- version = "1.3.0"
3
+ version = "1.4.0"
4
4
  description = "CLI for the Data Legion API — agent-friendly, fully async"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -25,6 +25,7 @@ classifiers = [
25
25
  "Programming Language :: Python :: 3.12",
26
26
  "Programming Language :: Python :: 3.13",
27
27
  "Programming Language :: Python :: 3.14",
28
+ "Programming Language :: Python :: 3.15",
28
29
  "Environment :: Console",
29
30
  "Typing :: Typed",
30
31
  ]
@@ -31,7 +31,6 @@ MinConfidence = Annotated[
31
31
  RequiredFields = Annotated[
32
32
  str | None, typer.Option("--required", help="Comma-separated required fields.")
33
33
  ]
34
- MultiOpt = Annotated[bool, typer.Option("--multiple", "-m", help="Return multiple matches.")]
35
34
 
36
35
 
37
36
  @app.command()
@@ -52,8 +51,6 @@ async def enrich(
52
51
  industry: Annotated[
53
52
  str | None, typer.Option("--industry", help="Industry (narrows name matching).")
54
53
  ] = None,
55
- multiple: MultiOpt = False,
56
- limit: LimitOpt = 2,
57
54
  min_confidence: MinConfidence = None,
58
55
  titlecase: TitleOpt = False,
59
56
  required_fields: RequiredFields = None,
@@ -67,7 +64,6 @@ async def enrich(
67
64
  datalegion-cli company enrich --domain google.com
68
65
  datalegion-cli company enrich --name "Acme Corp" --industry "Software"
69
66
  datalegion-cli company enrich --ticker AAPL --fields "name,industry,revenue"
70
- datalegion-cli company enrich --linkedin-id 1441 --multiple --limit 5
71
67
  echo '{"domain":"stripe.com"}' | datalegion-cli company enrich --stdin
72
68
  """
73
69
  if stdin:
@@ -81,8 +77,6 @@ async def enrich(
81
77
  social_url=social_url,
82
78
  ticker_symbol=ticker_symbol,
83
79
  industry=industry,
84
- multiple_results=multiple,
85
- limit=limit,
86
80
  min_confidence=min_confidence,
87
81
  titlecase=titlecase,
88
82
  required_fields=required_fields,
@@ -168,8 +162,6 @@ async def discover(
168
162
  # @async_command
169
163
  # async def bulk(
170
164
  # file: Annotated[str, typer.Argument(help="Path to JSON file with items array, or '-' for stdin.")],
171
- # multiple: MultiOpt = False,
172
- # limit: LimitOpt = 2,
173
165
  # titlecase: TitleOpt = False,
174
166
  # ) -> None:
175
167
  # """Bulk enrich up to 100 companies from a JSON file."""
@@ -184,8 +176,7 @@ async def discover(
184
176
  # client = LegionClient()
185
177
  # try:
186
178
  # result = await client.company_bulk(
187
- # items=items, multiple_results=multiple,
188
- # limit=limit, titlecase=titlecase,
179
+ # items=items, titlecase=titlecase,
189
180
  # )
190
181
  # emit_json(result)
191
182
  # emit_credits(client.last_credits_used, client.last_credits_remaining)
@@ -31,7 +31,6 @@ MinConfidence = Annotated[
31
31
  RequiredFields = Annotated[
32
32
  str | None, typer.Option("--required", help="Comma-separated required fields.")
33
33
  ]
34
- MultiOpt = Annotated[bool, typer.Option("--multiple", "-m", help="Return multiple matches.")]
35
34
 
36
35
 
37
36
  @app.command()
@@ -67,8 +66,6 @@ async def enrich(
67
66
  postal_code: Annotated[
68
67
  str | None, typer.Option("--postal-code", help="Postal/ZIP code.")
69
68
  ] = None,
70
- multiple: MultiOpt = False,
71
- limit: LimitOpt = 2,
72
69
  min_confidence: MinConfidence = None,
73
70
  titlecase: TitleOpt = False,
74
71
  required_fields: RequiredFields = None,
@@ -82,7 +79,6 @@ async def enrich(
82
79
  datalegion-cli person enrich --email john@example.com
83
80
  datalegion-cli person enrich --name "Jane Doe" --company "Acme Corp"
84
81
  datalegion-cli person enrich --phone "+14155551234" --fields "name,email,title"
85
- datalegion-cli person enrich --linkedin-id 12345 --multiple --limit 3
86
82
  echo '{"email":"jane@example.com"}' | datalegion-cli person enrich --stdin
87
83
  """
88
84
  if stdin:
@@ -107,8 +103,6 @@ async def enrich(
107
103
  birth_date=birth_date,
108
104
  address=address,
109
105
  postal_code=postal_code,
110
- multiple_results=multiple,
111
- limit=limit,
112
106
  min_confidence=min_confidence,
113
107
  titlecase=titlecase,
114
108
  required_fields=required_fields,
@@ -194,8 +188,6 @@ async def discover(
194
188
  # @async_command
195
189
  # async def bulk(
196
190
  # file: Annotated[str, typer.Argument(help="Path to JSON file with items array, or '-' for stdin.")],
197
- # multiple: MultiOpt = False,
198
- # limit: LimitOpt = 2,
199
191
  # titlecase: TitleOpt = False,
200
192
  # ) -> None:
201
193
  # """Bulk enrich up to 100 people from a JSON file."""
@@ -211,8 +203,7 @@ async def discover(
211
203
  # client = LegionClient()
212
204
  # try:
213
205
  # result = await client.person_bulk(
214
- # items=items, multiple_results=multiple,
215
- # limit=limit, titlecase=titlecase,
206
+ # items=items, titlecase=titlecase,
216
207
  # )
217
208
  # emit_json(result)
218
209
  # emit_credits(client.last_credits_used, client.last_credits_remaining)
@@ -27,6 +27,7 @@ _DEFAULTS: dict[str, object] = {
27
27
  "api_key": "",
28
28
  "default_output": "json", # json | table | raw
29
29
  "install_method": "", # brew | github | git | pip
30
+ "device_id": "", # random name for this machine's login key (see login.new_device_id)
30
31
  }
31
32
 
32
33
  # Fields that are stored encrypted on disk
@@ -12,8 +12,8 @@ from __future__ import annotations
12
12
 
13
13
  import asyncio
14
14
  import os
15
- import platform
16
15
  import re
16
+ import secrets
17
17
  from typing import TYPE_CHECKING, Any
18
18
 
19
19
  if TYPE_CHECKING:
@@ -40,10 +40,15 @@ class LoginError(Exception):
40
40
  self.details = details
41
41
 
42
42
 
43
- def default_device_name() -> str:
44
- """This machine's name in the form the API accepts, or 'cli' when it has none."""
45
- name = re.sub(r"[^\w.@:-]+", "-", platform.node()).strip("-")[:100]
46
- return name or "cli"
43
+ def new_device_id() -> str:
44
+ """A random name for this machine's key: ``cli-`` plus 8 hex characters.
45
+
46
+ Random rather than the hostname (or a hash of it): hostnames often carry a
47
+ person's name and are guessable, so nothing about the machine leaves it. Saved
48
+ in the config on first login and reused, so signing in again replaces this
49
+ machine's key instead of adding another.
50
+ """
51
+ return f"cli-{secrets.token_hex(4)}"
47
52
 
48
53
 
49
54
  def check_device_name(name: str) -> str:
@@ -126,7 +126,10 @@ async def login(
126
126
  int | None, typer.Option("--team-id", help="Team the key bills, when you have several.")
127
127
  ] = None,
128
128
  device: Annotated[
129
- str | None, typer.Option("--device", help="Name for this machine (default: hostname).")
129
+ str | None,
130
+ typer.Option(
131
+ "--device", help="Name for this machine (default: a random id saved locally)."
132
+ ),
130
133
  ] = None,
131
134
  no_browser: Annotated[
132
135
  bool, typer.Option("--no-browser", help="Print the sign-in link without opening it.")
@@ -145,7 +148,11 @@ async def login(
145
148
  from datalegion_cli import login as flow
146
149
 
147
150
  try:
148
- device_name = flow.check_device_name(device or flow.default_device_name())
151
+ cfg = load_config()
152
+ if not device and not cfg.get("device_id"):
153
+ cfg["device_id"] = flow.new_device_id()
154
+ save_config(cfg)
155
+ device_name = flow.check_device_name(device or str(cfg["device_id"]))
149
156
  async with httpx.AsyncClient(timeout=30.0) as client:
150
157
  started = await flow.start_device_authorization(client)
151
158
  link = started.get("verification_uri_complete") or started["verification_uri"]
@@ -438,3 +438,31 @@ class TestCreditsUsage:
438
438
  with _mock_client_request(response):
439
439
  result = runner.invoke(app, ["credits", "usage"])
440
440
  assert result.exit_code == 0
441
+
442
+
443
+ # ── Several matches per lookup is an enterprise feature: no CLI option ──
444
+
445
+
446
+ class TestEnrichOffersNoMultipleResults:
447
+ def test_enrich_rejects_multiple_and_limit(self, monkeypatch):
448
+ _mock_config(monkeypatch)
449
+ for entity, ident in (("person", ["--email", "a@b.co"]), ("company", ["--domain", "b.co"])):
450
+ for option in (["--multiple"], ["--limit", "3"]):
451
+ result = runner.invoke(app, [entity, "enrich", *ident, *option])
452
+ assert result.exit_code != 0, (entity, option)
453
+
454
+ def test_enrich_payload_carries_neither_field(self, monkeypatch):
455
+ _mock_config(monkeypatch)
456
+ sent: list[dict] = []
457
+
458
+ async def capture(self, method, endpoint, *, payload=None, params=None):
459
+ sent.append(payload or {})
460
+ return {"matches": [], "total": 0}
461
+
462
+ with patch("datalegion_cli.client.LegionClient.request", capture):
463
+ runner.invoke(app, ["person", "enrich", "--email", "a@b.co"])
464
+ runner.invoke(app, ["company", "enrich", "--domain", "b.co"])
465
+ assert len(sent) == 2
466
+ for payload in sent:
467
+ assert "multiple_results" not in payload
468
+ assert "limit" not in payload
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import json
6
+ import re
6
7
  from unittest.mock import AsyncMock, patch
7
8
 
8
9
  import httpx
@@ -32,13 +33,15 @@ def tmp_config(tmp_config_dir, monkeypatch):
32
33
 
33
34
 
34
35
  class TestDeviceName:
35
- def test_default_is_the_hostname_made_safe(self, monkeypatch):
36
- monkeypatch.setattr(flow.platform, "node", lambda: "Jack's MacBook Pro.local")
37
- assert flow.default_device_name() == "Jack-s-MacBook-Pro.local"
36
+ def test_new_ids_are_random_and_api_safe(self):
37
+ ids = {flow.new_device_id() for _ in range(50)}
38
+ assert len(ids) == 50
39
+ for device_id in ids:
40
+ assert re.fullmatch(r"cli-[0-9a-f]{8}", device_id)
41
+ assert flow.check_device_name(device_id) == device_id
38
42
 
39
- def test_default_without_a_hostname(self, monkeypatch):
40
- monkeypatch.setattr(flow.platform, "node", lambda: "")
41
- assert flow.default_device_name() == "cli"
43
+ def test_the_hostname_is_never_read(self):
44
+ assert not hasattr(flow, "platform")
42
45
 
43
46
  @pytest.mark.parametrize("name", ["", " lead", "a\nb", "x" * 101, "semi;colon", "two spaces"])
44
47
  def test_rejects_what_the_api_rejects(self, name):
@@ -181,6 +184,27 @@ class TestLoginCommand:
181
184
 
182
185
  assert load_config()["api_key"] == KEY
183
186
 
187
+ def test_default_device_is_a_saved_random_id_reused_next_time(self, steps, tmp_config):
188
+ exchange, _ = steps
189
+ assert runner.invoke(app, ["login"]).exit_code == 0
190
+ first = exchange.await_args.args[3]
191
+ assert re.fullmatch(r"cli-[0-9a-f]{8}", first)
192
+ from datalegion_cli.config import load_config
193
+
194
+ assert load_config()["device_id"] == first
195
+ assert runner.invoke(app, ["login"]).exit_code == 0
196
+ assert exchange.await_args.args[3] == first # same machine, same key slot
197
+
198
+ def test_device_flag_wins_and_leaves_the_saved_id(self, steps, tmp_config):
199
+ exchange, _ = steps
200
+ assert runner.invoke(app, ["login"]).exit_code == 0
201
+ from datalegion_cli.config import load_config
202
+
203
+ saved = load_config()["device_id"]
204
+ assert runner.invoke(app, ["login", "--device", "laptop"]).exit_code == 0
205
+ assert exchange.await_args.args[3] == "laptop"
206
+ assert load_config()["device_id"] == saved
207
+
184
208
  def test_no_browser(self, steps, tmp_config):
185
209
  _, browser = steps
186
210
  assert runner.invoke(app, ["login", "--device", "laptop", "--no-browser"]).exit_code == 0