Skip to content

Commit 83d0f80

Browse files
committed
Add nats-server package
Signed-off-by: Casper Beyer <[email protected]>
1 parent 1520289 commit 83d0f80

File tree

10 files changed

+663
-2
lines changed

10 files changed

+663
-2
lines changed

.github/workflows/test.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- "**"
1010

1111
jobs:
12-
test:
12+
nats:
1313
runs-on: ubuntu-latest
1414
timeout-minutes: 20
1515
env:
@@ -42,6 +42,43 @@ jobs:
4242
- name: Run tests
4343
run: |
4444
pipenv run flake8 --ignore="W391, W503, W504" ./nats/js/
45-
pipenv run pytest -x -vv -s --continue-on-collection-errors
45+
pipenv run pytest -x -vv -s --continue-on-collection-errors ./tests
4646
env:
4747
PATH: $HOME/nats-server:$PATH
48+
49+
project:
50+
name: ${{ matrix.project }} (python-${{ matrix.python-version }}, nats-server-${{ matrix.nats-server-version }}, ${{ matrix.os }})
51+
runs-on: ${{ matrix.os }}
52+
strategy:
53+
matrix:
54+
python-version: ["3.11", "3.12", "3.13"]
55+
os: ["ubuntu-latest", "macos-latest"]
56+
nats-server-version: ["latest"]
57+
project: ["nats-server"]
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v2
61+
62+
- name: Set up Go
63+
uses: actions/setup-go@v2
64+
with:
65+
go-version: "1.23.4"
66+
67+
- name: Install NATS Server
68+
run: |
69+
go install github.com/nats-io/nats-server/v2@${{ matrix.nats-server-version }}
70+
shell: bash
71+
72+
- name: Set up Python ${{ matrix.python-version }}
73+
uses: actions/setup-python@v2
74+
with:
75+
python-version: ${{ matrix.python-version }}
76+
77+
- name: Install hatch
78+
run: |
79+
python -m pip install --upgrade pip
80+
pip install hatch
81+
82+
- name: Run tests for ${{ matrix.project }}
83+
run: hatch test -v
84+
working-directory: ${{ matrix.project }}

nats-server/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# NATS Server for Python
2+
3+
Manage NATS server instances from python.
4+
5+
## Features
6+
7+
- Asynchronous server control
8+
9+
## Installation
10+
11+
```bash
12+
pip install nats-server
13+
```
14+
15+
Requires Python 3.8+ and the NATS server binary in your PATH.
16+
17+
## Usage
18+
19+
```python
20+
import asyncio
21+
import nats.server
22+
23+
async def main():
24+
# Start server with auto port assignment
25+
server = await nats.server.run(port=0, jetstream=True)
26+
print(f"Server running on {server.host}:{server.port}")
27+
28+
# Do something with the server...
29+
30+
# Clean shutdown
31+
await server.shutdown()
32+
33+
asyncio.run(main())
34+
```
35+
36+
## License
37+
38+
MIT
39+
40+
## Contributing
41+
42+
Contributions welcome. Submit a Pull Request on GitHub.

nats-server/pyproject.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "nats-server"
7+
version = "0.0.0"
8+
description = 'Python library for managing NATS servers for development and testing'
9+
readme = "README.md"
10+
requires-python = ">=3.8"
11+
license = "MIT"
12+
keywords = ["nats", "messaging", "testing"]
13+
authors = [
14+
{ name = "Casper Beyer", email = "[email protected]" },
15+
]
16+
classifiers = [
17+
"Development Status :: 4 - Beta",
18+
"Programming Language :: Python",
19+
"Programming Language :: Python :: 3.8",
20+
"Programming Language :: Python :: 3.9",
21+
"Programming Language :: Python :: 3.10",
22+
"Programming Language :: Python :: 3.11",
23+
"Programming Language :: Python :: 3.12",
24+
"Programming Language :: Python :: Implementation :: CPython",
25+
"Programming Language :: Python :: Implementation :: PyPy",
26+
]
27+
dependencies = [
28+
"typing-extensions>=4.0"
29+
]
30+
31+
[project.urls]
32+
Documentation = "https://github.com/caspervonb/nats.py"
33+
Issues = "https://github.com/caspervonb/nats.py/issues"
34+
Source = "https://github.com/caspervonb/nats.py"
35+
36+
[tool.hatch.metadata]
37+
allow-direct-references = true
38+
39+
[tool.hatch.build.targets.wheel]
40+
packages = ["src/nats"]
41+
42+
[tool.hatch.build.targets.sdist]
43+
include = [
44+
"/src",
45+
"/tests",
46+
]
47+
48+
[tool.hatch.envs.hatch-test]
49+
extra-dependencies = [
50+
"pytest-asyncio>=0.21.0",
51+
]
52+
53+
[tool.pytest.ini_options]
54+
asyncio_default_fixture_loop_scope = "function"
55+
asyncio_mode = "auto"
56+
57+
[tool.ruff.lint]
58+
ignore = ["TRY301", "S104"]

0 commit comments

Comments
 (0)