Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions python/natsrpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from . import js
from . import exceptions, js
from ._natsrpy_rs import CallbackSubscription, IteratorSubscription, Message, Nats

__all__ = ["CallbackSubscription", "IteratorSubscription", "Message", "Nats", "js"]
__all__ = [
"CallbackSubscription",
"IteratorSubscription",
"Message",
"Nats",
"exceptions",
"js",
]
11 changes: 9 additions & 2 deletions python/natsrpy/_natsrpy_rs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from typing import Any, final, overload

from typing_extensions import Self

from . import js
from . import exceptions, js

@final
class Message:
Expand Down Expand Up @@ -107,4 +107,11 @@ class Nats:
backpressure_on_inflight: bool | None = None,
) -> js.JetStream: ...

__all__ = ["CallbackSubscription", "IteratorSubscription", "Message", "Nats", "js"]
__all__ = [
"CallbackSubscription",
"IteratorSubscription",
"Message",
"Nats",
"exceptions",
"js",
]
9 changes: 9 additions & 0 deletions python/natsrpy/_natsrpy_rs/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class NatsrpyBaseError(Exception): ...
class NatsrpySessionError(NatsrpyBaseError): ...
class NatsrpyPublishError(NatsrpyBaseError): ...

__all__ = [
"NatsrpyBaseError",
"NatsrpyPublishError",
"NatsrpySessionError",
]
11 changes: 11 additions & 0 deletions python/natsrpy/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ._natsrpy_rs.exceptions import (
NatsrpyBaseError,
NatsrpyPublishError,
NatsrpySessionError,
)

__all__ = [
"NatsrpyBaseError",
"NatsrpyPublishError",
"NatsrpySessionError",
]
11 changes: 10 additions & 1 deletion python/natsrpy/js.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
ReplayPolicy,
)
from ._natsrpy_rs.js.kv import KeyValue, KVConfig
from ._natsrpy_rs.js.object_store import ObjectStore, ObjectStoreConfig
from ._natsrpy_rs.js.object_store import (
ObjectInfo,
ObjectInfoIterator,
ObjectLink,
ObjectStore,
ObjectStoreConfig,
)
from ._natsrpy_rs.js.stream import (
Compression,
ConsumerLimits,
Expand Down Expand Up @@ -38,6 +44,9 @@
"JetStream",
"KVConfig",
"KeyValue",
"ObjectInfo",
"ObjectInfoIterator",
"ObjectLink",
"ObjectStore",
"ObjectStoreConfig",
"PersistenceMode",
Expand Down
7 changes: 4 additions & 3 deletions python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ async def nats(nats_url: str) -> AsyncGenerator[Nats, None]:
nats = Nats(addrs=[nats_url])
await nats.startup()

yield nats

await nats.shutdown()
try:
yield nats
finally:
await nats.shutdown()


@pytest.fixture(scope="session")
Expand Down
6 changes: 2 additions & 4 deletions python/tests/test_object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
from pathlib import Path

import pytest
from natsrpy._natsrpy_rs.js.object_store import (
from natsrpy.js import (
JetStream,
ObjectInfo,
ObjectInfoIterator,
ObjectLink,
)
from natsrpy.js import (
JetStream,
ObjectStore,
ObjectStoreConfig,
StorageType,
Expand Down
13 changes: 5 additions & 8 deletions src/js/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,15 @@ impl KeyValue {
) -> NatsrpyResult<Bound<'py, PyAny>> {
let store = self.store.clone();
let data = bytes::Bytes::copy_from_slice(value.as_bytes());
natsrpy_future(py, async move {
let status = store.read().await.put(key, data).await?;
Ok(status)
})
natsrpy_future(
py,
async move { Ok(store.read().await.put(key, data).await?) },
)
}

pub fn delete<'py>(&self, py: Python<'py>, key: String) -> NatsrpyResult<Bound<'py, PyAny>> {
let store = self.store.clone();
natsrpy_future(py, async move {
let kv = store.read().await;
Ok(kv.delete(key).await?)
})
natsrpy_future(py, async move { Ok(store.read().await.delete(key).await?) })
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub mod _natsrpy_rs {
#[pymodule_export]
use super::subscriptions::{callback::CallbackSubscription, iterator::IteratorSubscription};

#[pymodule_export]
use super::exceptions::py_err::pymod as exceptions;

#[pymodule_export]
use super::js::pymod as js;

Expand Down
1 change: 1 addition & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod headers;
pub mod py;
pub mod py_types;
pub mod streamer;

pub use futures::natsrpy_future;
Loading