nashpit 0.1.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 (60) hide show
  1. nashpit-0.1.0/PKG-INFO +105 -0
  2. nashpit-0.1.0/README.md +75 -0
  3. nashpit-0.1.0/pyproject.toml +153 -0
  4. nashpit-0.1.0/pyproject.toml.orig +99 -0
  5. nashpit-0.1.0/src/nashpit/__init__.py +109 -0
  6. nashpit-0.1.0/src/nashpit/_cli_shim.py +48 -0
  7. nashpit-0.1.0/src/nashpit/_keys.py +87 -0
  8. nashpit-0.1.0/src/nashpit/_proto/__init__.py +4 -0
  9. nashpit-0.1.0/src/nashpit/_proto/v1/__init__.py +1 -0
  10. nashpit-0.1.0/src/nashpit/_proto/v1/account_pb2.py +87 -0
  11. nashpit-0.1.0/src/nashpit/_proto/v1/account_pb2.pyi +146 -0
  12. nashpit-0.1.0/src/nashpit/_proto/v1/auth_pb2.py +108 -0
  13. nashpit-0.1.0/src/nashpit/_proto/v1/auth_pb2.pyi +182 -0
  14. nashpit-0.1.0/src/nashpit/_proto/v1/bot_pb2.py +77 -0
  15. nashpit-0.1.0/src/nashpit/_proto/v1/bot_pb2.pyi +148 -0
  16. nashpit-0.1.0/src/nashpit/_proto/v1/common_pb2.py +82 -0
  17. nashpit-0.1.0/src/nashpit/_proto/v1/common_pb2.pyi +255 -0
  18. nashpit-0.1.0/src/nashpit/_proto/v1/hand_pb2.py +96 -0
  19. nashpit-0.1.0/src/nashpit/_proto/v1/hand_pb2.pyi +292 -0
  20. nashpit-0.1.0/src/nashpit/_proto/v1/invite_pb2.py +79 -0
  21. nashpit-0.1.0/src/nashpit/_proto/v1/invite_pb2.pyi +126 -0
  22. nashpit-0.1.0/src/nashpit/_proto/v1/key_pb2.py +69 -0
  23. nashpit-0.1.0/src/nashpit/_proto/v1/key_pb2.pyi +104 -0
  24. nashpit-0.1.0/src/nashpit/_proto/v1/money_pb2.py +159 -0
  25. nashpit-0.1.0/src/nashpit/_proto/v1/money_pb2.pyi +469 -0
  26. nashpit-0.1.0/src/nashpit/_proto/v1/options_pb2.py +41 -0
  27. nashpit-0.1.0/src/nashpit/_proto/v1/options_pb2.pyi +57 -0
  28. nashpit-0.1.0/src/nashpit/_proto/v1/platform_pb2.py +62 -0
  29. nashpit-0.1.0/src/nashpit/_proto/v1/platform_pb2.pyi +65 -0
  30. nashpit-0.1.0/src/nashpit/_proto/v1/play_pb2.py +55 -0
  31. nashpit-0.1.0/src/nashpit/_proto/v1/play_pb2.pyi +57 -0
  32. nashpit-0.1.0/src/nashpit/_proto/v1/profile_pb2.py +80 -0
  33. nashpit-0.1.0/src/nashpit/_proto/v1/profile_pb2.pyi +135 -0
  34. nashpit-0.1.0/src/nashpit/_proto/v1/rating_pb2.py +59 -0
  35. nashpit-0.1.0/src/nashpit/_proto/v1/rating_pb2.pyi +76 -0
  36. nashpit-0.1.0/src/nashpit/_proto/v1/run_pb2.py +102 -0
  37. nashpit-0.1.0/src/nashpit/_proto/v1/run_pb2.pyi +282 -0
  38. nashpit-0.1.0/src/nashpit/_proto/v1/sync_pb2.py +79 -0
  39. nashpit-0.1.0/src/nashpit/_proto/v1/sync_pb2.pyi +178 -0
  40. nashpit-0.1.0/src/nashpit/_proto/v1/table_pb2.py +89 -0
  41. nashpit-0.1.0/src/nashpit/_proto/v1/table_pb2.pyi +283 -0
  42. nashpit-0.1.0/src/nashpit/_proto/v1/transfer_pb2.py +57 -0
  43. nashpit-0.1.0/src/nashpit/_proto/v1/transfer_pb2.pyi +70 -0
  44. nashpit-0.1.0/src/nashpit/_proto/v1/ws_pb2.py +219 -0
  45. nashpit-0.1.0/src/nashpit/_proto/v1/ws_pb2.pyi +681 -0
  46. nashpit-0.1.0/src/nashpit/_proto/wire.py +54 -0
  47. nashpit-0.1.0/src/nashpit/_run.py +108 -0
  48. nashpit-0.1.0/src/nashpit/_runtime.py +946 -0
  49. nashpit-0.1.0/src/nashpit/_telemetry.py +548 -0
  50. nashpit-0.1.0/src/nashpit/_usage.py +432 -0
  51. nashpit-0.1.0/src/nashpit/_version.py +2 -0
  52. nashpit-0.1.0/src/nashpit/_wire.py +350 -0
  53. nashpit-0.1.0/src/nashpit/bot.py +89 -0
  54. nashpit-0.1.0/src/nashpit/cards.py +167 -0
  55. nashpit-0.1.0/src/nashpit/errors.py +129 -0
  56. nashpit-0.1.0/src/nashpit/house/__init__.py +5 -0
  57. nashpit-0.1.0/src/nashpit/house/fast.py +219 -0
  58. nashpit-0.1.0/src/nashpit/models.py +624 -0
  59. nashpit-0.1.0/src/nashpit/py.typed +0 -0
  60. nashpit-0.1.0/src/nashpit/version_hash.py +156 -0
nashpit-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.4
2
+ Name: nashpit
3
+ Version: 0.1.0
4
+ Summary: Python SDK and CLI for Nashpit: heads-up No-Limit Hold'em for bots
5
+ Keywords: poker,bots,nlhe,heads-up,nashpit
6
+ Author: Nashpit
7
+ License-Expression: MIT
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
17
+ Classifier: Typing :: Typed
18
+ Requires-Dist: pydantic>=2.11,<3
19
+ Requires-Dist: websockets>=15,<18
20
+ Requires-Dist: blake3>=1.0,<2
21
+ Requires-Dist: pathspec>=0.12,<2
22
+ Requires-Dist: protobuf>=7.35.1,<8
23
+ Requires-Dist: nashpit-cli==0.1.0
24
+ Requires-Dist: sentry-sdk>=2.20,<3
25
+ Requires-Python: >=3.11
26
+ Project-URL: Homepage, https://nashpit.xyz
27
+ Project-URL: Documentation, https://docs.nashpit.xyz
28
+ Project-URL: Repository, https://github.com/furiousteabag/nashpit
29
+ Description-Content-Type: text/markdown
30
+
31
+ # nashpit
32
+
33
+ Python SDK for [Nashpit](https://nashpit.xyz): heads-up No-Limit Hold'em for bots, real money.
34
+
35
+ ```bash
36
+ uv tool install nashpit # the `nashpit` CLI (Rust binary, no toolchain needed)
37
+ nashpit init shark && cd shark
38
+ nashpit sim # local, no money: vs house:fast on the same engine
39
+ nashpit check # local validation suite
40
+ ```
41
+
42
+ ```python
43
+ import nashpit
44
+
45
+
46
+ class Shark(nashpit.Bot):
47
+ def decide(self, s: nashpit.State) -> nashpit.Action:
48
+ if s.street == "preflop" and s.hole_cards.is_pair():
49
+ return s.raise_to_bb(3) # clamped to the legal range
50
+ if s.legal.can_check:
51
+ return s.check() # fold is never offered when check is free
52
+ return s.call() if s.pot_odds < 0.25 else s.fold()
53
+
54
+
55
+ nashpit.run(Shark())
56
+ ```
57
+
58
+ - Fully typed (`py.typed`, pyright strict and mypy strict clean), pydantic v2 frozen models.
59
+ - Helpers on `State` (`check`, `call`, `raise_to`, `raise_to_bb`, `bet_pot`, `all_in`) can
60
+ never produce an illegal action.
61
+ - One WebSocket serves hundreds of tables; reconnect and resume, deadline watchdog with a
62
+ fallback action, thread or process pool for heavy `decide`.
63
+ - Optional hooks: `setup`, `buy_in`, `before_hand` (`Continue`/`TopUp`/`Leave`), `on_hand_end`,
64
+ `on_match_end`, `on_event`, `fallback`. Each may be `def` or `async def`.
65
+
66
+ Docs: https://docs.nashpit.xyz (for agents: https://docs.nashpit.xyz/llms.txt).
67
+
68
+ ## Usage events and error reporting
69
+
70
+ The SDK tells us how it is doing so we can find bugs and slow spots. Everything it sends is
71
+ listed field by field on https://docs.nashpit.xyz/data-we-collect.
72
+
73
+ **Usage events** go to the API your bot plays against (`https://api.nashpit.xyz/v1/telemetry/events`
74
+ for `wss://api.nashpit.xyz/v1/ws`), never to another host: process start (Python version, OS,
75
+ architecture, whether the API is a local stack), connection attempts (outcome, our error code,
76
+ duration, the connection's request id), disconnects (close code, how long it was up), every
77
+ 60 seconds while playing and at exit the number of decisions with their latency percentiles,
78
+ timeouts and failures, where an SDK error happened with the SDK's exception type (an error
79
+ raised by your own code is sent only as `bot`, without its type or message), and why and after
80
+ how long the process stopped. Never your bot's name, code, keys, file paths, host name, cards,
81
+ game state or decisions. They are collected in a bounded queue and sent by a background thread
82
+ every few seconds and at exit (at most 1.5 s); a failed send is dropped and never affects the
83
+ bot.
84
+
85
+ **Error reports:** when code inside the `nashpit` package itself fails (connection and runtime
86
+ loop, protocol decoding, internal invariants), the SDK sends an error report to Nashpit
87
+ (`api.nashpit.xyz`, via a private Sentry client) so we can fix SDK bugs. It never touches a
88
+ Sentry setup of your own.
89
+
90
+ - **Sent:** exception type, a message with keys (`np_...`), emails and home-directory user names
91
+ redacted (max 500 characters), stack frames inside the `nashpit` package only (as
92
+ `nashpit/<file>.py`, function, line), SDK version, Python version and implementation, OS name
93
+ and version, and whether the table was `prod` or `test`.
94
+ - **Never sent:** errors from your bot's code (`decide` and every hook, including nashpit helpers
95
+ called from them), game state or cards, keys, local variables, source code, your file paths,
96
+ hostname, environment variables, logs or breadcrumbs.
97
+ - At most one report per distinct error and 20 per process; sending happens in a background
98
+ thread and can never slow down or break the bot.
99
+ - Bots started by the CLI (`nashpit sim`, `nashpit check`, `nashpit up`) never send error
100
+ reports.
101
+
102
+ **Opt out** (both): set `NASHPIT_TELEMETRY=0` (or `false`/`off`/`no`) or `DO_NOT_TRACK=1`, in the
103
+ environment or in the bot's `.env`. Nothing is then created or sent. Both are also off in CI
104
+ (when `CI` is set) unless you set `NASHPIT_TELEMETRY=1`, and usage events against any API but
105
+ production (a local stack) are sent only with `NASHPIT_TELEMETRY=1`.
@@ -0,0 +1,75 @@
1
+ # nashpit
2
+
3
+ Python SDK for [Nashpit](https://nashpit.xyz): heads-up No-Limit Hold'em for bots, real money.
4
+
5
+ ```bash
6
+ uv tool install nashpit # the `nashpit` CLI (Rust binary, no toolchain needed)
7
+ nashpit init shark && cd shark
8
+ nashpit sim # local, no money: vs house:fast on the same engine
9
+ nashpit check # local validation suite
10
+ ```
11
+
12
+ ```python
13
+ import nashpit
14
+
15
+
16
+ class Shark(nashpit.Bot):
17
+ def decide(self, s: nashpit.State) -> nashpit.Action:
18
+ if s.street == "preflop" and s.hole_cards.is_pair():
19
+ return s.raise_to_bb(3) # clamped to the legal range
20
+ if s.legal.can_check:
21
+ return s.check() # fold is never offered when check is free
22
+ return s.call() if s.pot_odds < 0.25 else s.fold()
23
+
24
+
25
+ nashpit.run(Shark())
26
+ ```
27
+
28
+ - Fully typed (`py.typed`, pyright strict and mypy strict clean), pydantic v2 frozen models.
29
+ - Helpers on `State` (`check`, `call`, `raise_to`, `raise_to_bb`, `bet_pot`, `all_in`) can
30
+ never produce an illegal action.
31
+ - One WebSocket serves hundreds of tables; reconnect and resume, deadline watchdog with a
32
+ fallback action, thread or process pool for heavy `decide`.
33
+ - Optional hooks: `setup`, `buy_in`, `before_hand` (`Continue`/`TopUp`/`Leave`), `on_hand_end`,
34
+ `on_match_end`, `on_event`, `fallback`. Each may be `def` or `async def`.
35
+
36
+ Docs: https://docs.nashpit.xyz (for agents: https://docs.nashpit.xyz/llms.txt).
37
+
38
+ ## Usage events and error reporting
39
+
40
+ The SDK tells us how it is doing so we can find bugs and slow spots. Everything it sends is
41
+ listed field by field on https://docs.nashpit.xyz/data-we-collect.
42
+
43
+ **Usage events** go to the API your bot plays against (`https://api.nashpit.xyz/v1/telemetry/events`
44
+ for `wss://api.nashpit.xyz/v1/ws`), never to another host: process start (Python version, OS,
45
+ architecture, whether the API is a local stack), connection attempts (outcome, our error code,
46
+ duration, the connection's request id), disconnects (close code, how long it was up), every
47
+ 60 seconds while playing and at exit the number of decisions with their latency percentiles,
48
+ timeouts and failures, where an SDK error happened with the SDK's exception type (an error
49
+ raised by your own code is sent only as `bot`, without its type or message), and why and after
50
+ how long the process stopped. Never your bot's name, code, keys, file paths, host name, cards,
51
+ game state or decisions. They are collected in a bounded queue and sent by a background thread
52
+ every few seconds and at exit (at most 1.5 s); a failed send is dropped and never affects the
53
+ bot.
54
+
55
+ **Error reports:** when code inside the `nashpit` package itself fails (connection and runtime
56
+ loop, protocol decoding, internal invariants), the SDK sends an error report to Nashpit
57
+ (`api.nashpit.xyz`, via a private Sentry client) so we can fix SDK bugs. It never touches a
58
+ Sentry setup of your own.
59
+
60
+ - **Sent:** exception type, a message with keys (`np_...`), emails and home-directory user names
61
+ redacted (max 500 characters), stack frames inside the `nashpit` package only (as
62
+ `nashpit/<file>.py`, function, line), SDK version, Python version and implementation, OS name
63
+ and version, and whether the table was `prod` or `test`.
64
+ - **Never sent:** errors from your bot's code (`decide` and every hook, including nashpit helpers
65
+ called from them), game state or cards, keys, local variables, source code, your file paths,
66
+ hostname, environment variables, logs or breadcrumbs.
67
+ - At most one report per distinct error and 20 per process; sending happens in a background
68
+ thread and can never slow down or break the bot.
69
+ - Bots started by the CLI (`nashpit sim`, `nashpit check`, `nashpit up`) never send error
70
+ reports.
71
+
72
+ **Opt out** (both): set `NASHPIT_TELEMETRY=0` (or `false`/`off`/`no`) or `DO_NOT_TRACK=1`, in the
73
+ environment or in the bot's `.env`. Nothing is then created or sent. Both are also off in CI
74
+ (when `CI` is set) unless you set `NASHPIT_TELEMETRY=1`, and usage events against any API but
75
+ production (a local stack) are sent only with `NASHPIT_TELEMETRY=1`.
@@ -0,0 +1,153 @@
1
+ [project]
2
+ name = "nashpit"
3
+ version = "0.1.0"
4
+ description = "Python SDK and CLI for Nashpit: heads-up No-Limit Hold'em for bots"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "MIT"
8
+ keywords = [
9
+ "poker",
10
+ "bots",
11
+ "nlhe",
12
+ "heads-up",
13
+ "nashpit",
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Programming Language :: Python :: 3.15",
25
+ "Typing :: Typed",
26
+ ]
27
+ dependencies = [
28
+ "pydantic>=2.11,<3",
29
+ "websockets>=15,<18",
30
+ "blake3>=1.0,<2",
31
+ "pathspec>=0.12,<2",
32
+ "protobuf>=7.35.1,<8",
33
+ "nashpit-cli==0.1.0",
34
+ "sentry-sdk>=2.20,<3",
35
+ ]
36
+
37
+ [[project.authors]]
38
+ name = "Nashpit"
39
+
40
+ [project.scripts]
41
+ nashpit = "nashpit._cli_shim:main"
42
+
43
+ [project.urls]
44
+ Homepage = "https://nashpit.xyz"
45
+ Documentation = "https://docs.nashpit.xyz"
46
+ Repository = "https://github.com/furiousteabag/nashpit"
47
+
48
+ [build-system]
49
+ requires = ["uv_build>=0.9,<0.15"]
50
+ build-backend = "uv_build"
51
+
52
+ [dependency-groups]
53
+ dev = [
54
+ "pytest>=8",
55
+ "pytest-asyncio>=1.0",
56
+ "pyright>=1.1.400",
57
+ "mypy>=1.15",
58
+ "ruff>=0.12",
59
+ "types-protobuf>=6",
60
+ ]
61
+
62
+ [tool.uv]
63
+ override-dependencies = ["nashpit-cli ; python_version < '0'"]
64
+
65
+ [tool.ruff]
66
+ line-length = 100
67
+ target-version = "py311"
68
+ extend-exclude = ["src/nashpit/_proto"]
69
+
70
+ [tool.ruff.lint]
71
+ select = [
72
+ "E",
73
+ "F",
74
+ "W",
75
+ "I",
76
+ "B",
77
+ "UP",
78
+ "N",
79
+ "S",
80
+ "C4",
81
+ "SIM",
82
+ "RUF",
83
+ "ANN",
84
+ "PT",
85
+ "PL",
86
+ "TRY",
87
+ "PERF",
88
+ "FBT",
89
+ "A",
90
+ "ASYNC",
91
+ "PIE",
92
+ "RET",
93
+ "TC",
94
+ ]
95
+ ignore = [
96
+ "PLR2004",
97
+ "TRY003",
98
+ "PLR0913",
99
+ "PLR0911",
100
+ "PLR0912",
101
+ "PLR0915",
102
+ "S101",
103
+ "TC001",
104
+ "TC003",
105
+ "PLC0415",
106
+ "TRY400",
107
+ "TRY300",
108
+ ]
109
+
110
+ [tool.ruff.lint.per-file-ignores]
111
+ "tests/**" = [
112
+ "ANN",
113
+ "S",
114
+ "PLR",
115
+ "FBT",
116
+ "PT011",
117
+ "SIM117",
118
+ "ASYNC",
119
+ "TRY",
120
+ "PLW",
121
+ ]
122
+
123
+ [tool.pyright]
124
+ include = [
125
+ "src",
126
+ "tests",
127
+ ]
128
+ exclude = [
129
+ "src/nashpit/_proto",
130
+ "**/__pycache__",
131
+ ".venv",
132
+ ]
133
+ pythonVersion = "3.11"
134
+ typeCheckingMode = "strict"
135
+
136
+ [tool.mypy]
137
+ strict = true
138
+ python_version = "3.11"
139
+ files = [
140
+ "src/nashpit",
141
+ "tests",
142
+ ]
143
+ exclude = ["src/nashpit/_proto/"]
144
+ plugins = ["pydantic.mypy"]
145
+
146
+ [[tool.mypy.overrides]]
147
+ module = ["nashpit._proto.*"]
148
+ ignore_errors = true
149
+
150
+ [tool.pytest.ini_options]
151
+ asyncio_mode = "auto"
152
+ asyncio_default_fixture_loop_scope = "function"
153
+ testpaths = ["tests"]
@@ -0,0 +1,99 @@
1
+ [project]
2
+ name = "nashpit"
3
+ version = "0.1.0"
4
+ description = "Python SDK and CLI for Nashpit: heads-up No-Limit Hold'em for bots"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "MIT"
8
+ authors = [{ name = "Nashpit" }]
9
+ keywords = ["poker", "bots", "nlhe", "heads-up", "nashpit"]
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Intended Audience :: Developers",
13
+ "Programming Language :: Python :: 3",
14
+ "Programming Language :: Python :: 3 :: Only",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
19
+ "Programming Language :: Python :: 3.15",
20
+ "Typing :: Typed",
21
+ ]
22
+ dependencies = [
23
+ "pydantic>=2.11,<3",
24
+ "websockets>=15,<18",
25
+ "blake3>=1.0,<2",
26
+ "pathspec>=0.12,<2",
27
+ "protobuf>=7.35.1,<8",
28
+ # The Rust CLI binary (`nashpit-cli`, platform wheels built with maturin). The `nashpit`
29
+ # console script of this package is a thin shim that execs it, so `uv tool install nashpit`
30
+ # gives the `nashpit` command. Inside this repo it is dropped via override-dependencies.
31
+ "nashpit-cli==0.1.0",
32
+ "sentry-sdk>=2.20,<3",
33
+ ]
34
+
35
+ [project.scripts]
36
+ nashpit = "nashpit._cli_shim:main"
37
+
38
+ [project.urls]
39
+ Homepage = "https://nashpit.xyz"
40
+ Documentation = "https://docs.nashpit.xyz"
41
+ Repository = "https://github.com/furiousteabag/nashpit"
42
+
43
+ [build-system]
44
+ requires = ["uv_build>=0.9,<0.15"]
45
+ build-backend = "uv_build"
46
+
47
+ [dependency-groups]
48
+ dev = [
49
+ "pytest>=8",
50
+ "pytest-asyncio>=1.0",
51
+ "pyright>=1.1.400",
52
+ "mypy>=1.15",
53
+ "ruff>=0.12",
54
+ "types-protobuf>=6",
55
+ ]
56
+
57
+ [tool.uv]
58
+ # Development inside the monorepo: the CLI is built with cargo, not installed from PyPI.
59
+ override-dependencies = ["nashpit-cli ; python_version < '0'"]
60
+
61
+ [tool.ruff]
62
+ line-length = 100
63
+ target-version = "py311"
64
+ extend-exclude = ["src/nashpit/_proto"]
65
+
66
+ [tool.ruff.lint]
67
+ select = [
68
+ "E", "F", "W", "I", "B", "UP", "N", "S", "C4", "SIM", "RUF", "ANN", "PT", "PL", "TRY",
69
+ "PERF", "FBT", "A", "ASYNC", "PIE", "RET", "TC",
70
+ ]
71
+ ignore = [
72
+ "PLR2004", "TRY003", "PLR0913", "PLR0911", "PLR0912", "PLR0915", "S101", "TC001", "TC003",
73
+ "PLC0415", "TRY400", "TRY300",
74
+ ]
75
+
76
+ [tool.ruff.lint.per-file-ignores]
77
+ "tests/**" = ["ANN", "S", "PLR", "FBT", "PT011", "SIM117", "ASYNC", "TRY", "PLW"]
78
+
79
+ [tool.pyright]
80
+ include = ["src", "tests"]
81
+ exclude = ["src/nashpit/_proto", "**/__pycache__", ".venv"]
82
+ pythonVersion = "3.11"
83
+ typeCheckingMode = "strict"
84
+
85
+ [tool.mypy]
86
+ strict = true
87
+ python_version = "3.11"
88
+ files = ["src/nashpit", "tests"]
89
+ exclude = ["src/nashpit/_proto/"]
90
+ plugins = ["pydantic.mypy"]
91
+
92
+ [[tool.mypy.overrides]]
93
+ module = ["nashpit._proto.*"]
94
+ ignore_errors = true
95
+
96
+ [tool.pytest.ini_options]
97
+ asyncio_mode = "auto"
98
+ asyncio_default_fixture_loop_scope = "function"
99
+ testpaths = ["tests"]
@@ -0,0 +1,109 @@
1
+ """Nashpit Python SDK: write ``decide(state)``, call ``nashpit.run``.
2
+
3
+ ```python
4
+ import nashpit
5
+
6
+
7
+ class Shark(nashpit.Bot):
8
+ def decide(self, s: nashpit.State) -> nashpit.Action:
9
+ return s.check() if s.legal.can_check else s.call()
10
+
11
+
12
+ if __name__ == "__main__": # needed for executor="process"
13
+ nashpit.run(Shark())
14
+ ```
15
+ """
16
+
17
+ from nashpit._run import run, serve
18
+ from nashpit._version import __version__
19
+ from nashpit.bot import Bot, DecideFn, MaybeAwaitable
20
+ from nashpit.cards import Card, HoleCards, Rank, Suit
21
+ from nashpit.errors import (
22
+ AuthenticationError,
23
+ ConfigurationError,
24
+ ConnectionLostError,
25
+ IllegalActionError,
26
+ IncompatibleProtocolError,
27
+ NashpitError,
28
+ ProtocolError,
29
+ RateLimitedError,
30
+ WrongKeyTypeError,
31
+ )
32
+ from nashpit.models import (
33
+ Action,
34
+ ActionKind,
35
+ ActionRecord,
36
+ BetweenHands,
37
+ BuyInContext,
38
+ Call,
39
+ Check,
40
+ Chips,
41
+ Clock,
42
+ Continue,
43
+ Fold,
44
+ HandRecord,
45
+ Leave,
46
+ Legal,
47
+ MatchSummary,
48
+ Opponent,
49
+ RaiseTo,
50
+ Rating,
51
+ Seat,
52
+ Stakes,
53
+ State,
54
+ Street,
55
+ TableEvent,
56
+ TableRules,
57
+ TableView,
58
+ TopUp,
59
+ )
60
+ from nashpit.version_hash import compute_version_hash
61
+
62
+ __all__ = [
63
+ "Action",
64
+ "ActionKind",
65
+ "ActionRecord",
66
+ "AuthenticationError",
67
+ "BetweenHands",
68
+ "Bot",
69
+ "BuyInContext",
70
+ "Call",
71
+ "Card",
72
+ "Check",
73
+ "Chips",
74
+ "Clock",
75
+ "ConfigurationError",
76
+ "ConnectionLostError",
77
+ "Continue",
78
+ "DecideFn",
79
+ "Fold",
80
+ "HandRecord",
81
+ "HoleCards",
82
+ "IllegalActionError",
83
+ "IncompatibleProtocolError",
84
+ "Leave",
85
+ "Legal",
86
+ "MatchSummary",
87
+ "MaybeAwaitable",
88
+ "NashpitError",
89
+ "Opponent",
90
+ "ProtocolError",
91
+ "RaiseTo",
92
+ "Rank",
93
+ "RateLimitedError",
94
+ "Rating",
95
+ "Seat",
96
+ "Stakes",
97
+ "State",
98
+ "Street",
99
+ "Suit",
100
+ "TableEvent",
101
+ "TableRules",
102
+ "TableView",
103
+ "TopUp",
104
+ "WrongKeyTypeError",
105
+ "__version__",
106
+ "compute_version_hash",
107
+ "run",
108
+ "serve",
109
+ ]
@@ -0,0 +1,48 @@
1
+ """The ``nashpit`` console script: execs the Rust CLI shipped in the ``nashpit-cli`` wheel."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import shutil
7
+ import subprocess
8
+ import sys
9
+ import sysconfig
10
+ from pathlib import Path
11
+
12
+ BINARY = "nashpit-cli"
13
+
14
+
15
+ def find_cli() -> str | None:
16
+ override = os.environ.get("NASHPIT_CLI")
17
+ if override:
18
+ return override
19
+ exe = BINARY + (".exe" if sys.platform == "win32" else "")
20
+ candidates = [
21
+ Path(sysconfig.get_path("scripts")) / exe,
22
+ Path(sys.executable).parent / exe,
23
+ ]
24
+ user_scheme = f"{os.name}_user"
25
+ if user_scheme in sysconfig.get_scheme_names():
26
+ candidates.append(Path(sysconfig.get_path("scripts", scheme=user_scheme)) / exe)
27
+ for c in candidates:
28
+ if c.is_file():
29
+ return str(c)
30
+ return shutil.which(BINARY)
31
+
32
+
33
+ def main() -> None:
34
+ cli = find_cli()
35
+ if cli is None:
36
+ sys.stderr.write(
37
+ "error: the Nashpit CLI binary (nashpit-cli) was not found.\n"
38
+ " Fix: uv tool install nashpit (or: uv add nashpit-cli)\n"
39
+ )
40
+ raise SystemExit(127)
41
+ args = [cli, *sys.argv[1:]]
42
+ if sys.platform == "win32":
43
+ raise SystemExit(subprocess.call(args)) # noqa: S603 - our own binary
44
+ os.execv(cli, args) # noqa: S606
45
+
46
+
47
+ if __name__ == "__main__":
48
+ main()
@@ -0,0 +1,87 @@
1
+ """Bot key loading. Keys are never logged and never put in URLs."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+
8
+ from pydantic import SecretStr
9
+
10
+ from nashpit.errors import ConfigurationError, WrongKeyTypeError
11
+
12
+ BOT_KEY_PREFIX = "np_bot_"
13
+ ACCOUNT_KEY_PREFIX = "np_acct_"
14
+ ENV_KEY = "NASHPIT_BOT_KEY"
15
+ ENV_URL = "NASHPIT_URL"
16
+ DEFAULT_URL = "wss://api.nashpit.xyz/v1/ws"
17
+
18
+
19
+ def read_dotenv(path: Path) -> dict[str, str]:
20
+ """Minimal ``.env`` parser: ``KEY=value`` lines, ``#`` comments, optional quotes."""
21
+ out: dict[str, str] = {}
22
+ try:
23
+ text = path.read_text(encoding="utf-8")
24
+ except FileNotFoundError:
25
+ return out
26
+ for raw in text.splitlines():
27
+ line = raw.strip()
28
+ if not line or line.startswith("#") or "=" not in line:
29
+ continue
30
+ line = line.removeprefix("export ").strip()
31
+ name, _, value = line.partition("=")
32
+ value = value.strip()
33
+ if len(value) >= 2 and value[0] == value[-1] and value[0] in "\"'":
34
+ value = value[1:-1]
35
+ out[name.strip()] = value
36
+ return out
37
+
38
+
39
+ def find_dotenv(start: Path) -> Path | None:
40
+ for d in (start, *start.parents):
41
+ candidate = d / ".env"
42
+ if candidate.is_file():
43
+ return candidate
44
+ if (d / "nashpit.toml").is_file():
45
+ return None
46
+ return None
47
+
48
+
49
+ def check_bot_key(key: str) -> SecretStr:
50
+ key = key.strip()
51
+ if key.startswith(ACCOUNT_KEY_PREFIX):
52
+ raise WrongKeyTypeError(
53
+ "An account key was given where a bot key is required.",
54
+ hint="Account keys must not run bots. Run `nashpit up` (or `nashpit keys`) in the bot "
55
+ "folder to write this bot's key to .env as NASHPIT_BOT_KEY.",
56
+ )
57
+ if not key:
58
+ raise ConfigurationError(
59
+ "No bot key: NASHPIT_BOT_KEY is not set.",
60
+ hint="Run `nashpit up` in the bot folder (it writes .env), or export NASHPIT_BOT_KEY.",
61
+ )
62
+ return SecretStr(key)
63
+
64
+
65
+ def load_bot_key(explicit: str | None = None, cwd: Path | None = None) -> SecretStr:
66
+ if explicit is not None:
67
+ return check_bot_key(explicit)
68
+ env = os.environ.get(ENV_KEY)
69
+ if env is None:
70
+ dotenv = find_dotenv(cwd or Path.cwd())
71
+ if dotenv is not None:
72
+ env = read_dotenv(dotenv).get(ENV_KEY)
73
+ return check_bot_key(env or "")
74
+
75
+
76
+ def load_url(explicit: str | None = None, cwd: Path | None = None) -> str:
77
+ if explicit:
78
+ return explicit
79
+ env = os.environ.get(ENV_URL)
80
+ if env:
81
+ return env
82
+ dotenv = find_dotenv(cwd or Path.cwd())
83
+ if dotenv is not None:
84
+ value = read_dotenv(dotenv).get(ENV_URL)
85
+ if value:
86
+ return value
87
+ return DEFAULT_URL
@@ -0,0 +1,4 @@
1
+ """Generated wire types for the Nashpit protocol. Do not edit; run proto/gen.sh.
2
+
3
+ Serialise with ``nashpit._proto.wire.to_wire`` / ``from_wire`` (proto3 JSON, snake_case names).
4
+ """
@@ -0,0 +1 @@
1
+ """Generated Nashpit v1 wire types (official protobuf runtime). Do not edit; run proto/gen.sh."""