swarmauri_keyprovider_inmemory 0.2.0.dev4__tar.gz → 0.2.1.dev9__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.
@@ -1,10 +1,12 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: swarmauri_keyprovider_inmemory
3
- Version: 0.2.0.dev4
3
+ Version: 0.2.1.dev9
4
4
  Summary: In-memory key provider for Swarmauri
5
- License: Apache-2.0
6
- Author: Swarmauri
7
- Author-email: opensource@swarmauri.com
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: swarmauri,sdk,standards,keyprovider,inmemory,key-management
8
+ Author: Jacob Stewart
9
+ Author-email: jacob@swarmauri.com
8
10
  Requires-Python: >=3.10,<3.13
9
11
  Classifier: License :: OSI Approved :: Apache Software License
10
12
  Classifier: Natural Language :: English
@@ -15,22 +17,52 @@ Classifier: Programming Language :: Python :: 3.13
15
17
  Classifier: Development Status :: 3 - Alpha
16
18
  Classifier: Topic :: Security :: Cryptography
17
19
  Classifier: Intended Audience :: Developers
20
+ Classifier: Programming Language :: Python
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3 :: Only
18
23
  Requires-Dist: swarmauri_base
19
24
  Requires-Dist: swarmauri_core
20
25
  Description-Content-Type: text/markdown
21
26
 
22
- ![Swamauri Logo](https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png)
27
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
28
+
29
+
30
+ <p align="center">
31
+ <a href="https://pypi.org/project/swarmauri_keyprovider_inmemory/">
32
+ <img src="https://img.shields.io/pypi/dm/swarmauri_keyprovider_inmemory" alt="PyPI - Downloads"/></a>
33
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_inmemory/">
34
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_inmemory.svg"/></a>
35
+ <a href="https://pypi.org/project/swarmauri_keyprovider_inmemory/">
36
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri_keyprovider_inmemory" alt="PyPI - Python Version"/></a>
37
+ <a href="https://pypi.org/project/swarmauri_keyprovider_inmemory/">
38
+ <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_inmemory" alt="PyPI - License"/></a>
39
+ <a href="https://pypi.org/project/swarmauri_keyprovider_inmemory/">
40
+ <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_inmemory?label=swarmauri_keyprovider_inmemory&color=green" alt="PyPI - swarmauri_keyprovider_inmemory"/></a>
41
+ </p>
42
+
43
+ ---
23
44
 
24
45
  # Swarmauri In‑Memory Key Provider
25
46
 
26
- Volatile, in‑memory key provider for Swarmauri. All key material is kept strictly in process memory (no disk writes). Ideal for testing, CI, and ephemeral gateways.
47
+ Volatile, in‑memory key provider for Swarmauri. All key material is kept strictly in process memory (no disk writes). Ideal for testing, CI, and ephemeral gateways where persistence is not desired. Not intended for long‑term or production storage of secrets.
27
48
 
28
49
  ## Installation
29
50
 
51
+ Install the package with your preferred Python tooling:
52
+
30
53
  ```bash
31
54
  pip install swarmauri_keyprovider_inmemory
32
55
  ```
33
56
 
57
+ ```bash
58
+ poetry add swarmauri_keyprovider_inmemory
59
+ ```
60
+
61
+ ```bash
62
+ pip install uv
63
+ uv pip install swarmauri_keyprovider_inmemory
64
+ ```
65
+
34
66
  ## Usage
35
67
 
36
68
  Create and manage symmetric (or opaque/asymmetric placeholder) keys entirely in memory. The snippet below creates a new symmetric key and returns a `KeyRef` with material present when allowed by the export policy.
@@ -38,7 +70,7 @@ Create and manage symmetric (or opaque/asymmetric placeholder) keys entirely in
38
70
  ```python
39
71
  import asyncio
40
72
  from swarmauri_keyprovider_inmemory import InMemoryKeyProvider
41
- from swarmauri_core.keys.types import (
73
+ from swarmauri_core.key_providers.types import (
42
74
  KeySpec,
43
75
  KeyClass,
44
76
  KeyAlg, # optional, not enforced by the provider
@@ -53,7 +85,7 @@ async def main() -> None:
53
85
  # Create a symmetric key kept only in memory
54
86
  spec = KeySpec(
55
87
  klass=KeyClass.symmetric,
56
- alg=KeyAlg.AES256, # optional hint – not strictly enforced
88
+ alg=KeyAlg.AES256_GCM, # optional hint – not strictly enforced
57
89
  uses=(KeyUse.ENCRYPT, KeyUse.DECRYPT),
58
90
  export_policy=ExportPolicy.SECRET_WHEN_ALLOWED, # material may be present
59
91
  label="session-key",
@@ -101,8 +133,19 @@ asyncio.run(main())
101
133
  - No persistence: data is lost when the process exits
102
134
  - Not supported: JWK/JWKS export (will raise `NotImplementedError`)
103
135
 
136
+ ## Security Considerations
137
+
138
+ - Keys exist only for the lifetime of the Python process; restarting drops all material.
139
+ - No hardware isolation or disk persistence is provided.
140
+ - Use only for development, CI, or other ephemeral scenarios.
141
+
104
142
  ## Notes
105
143
 
106
144
  - Exported `KeyRef.material` presence depends on the `ExportPolicy`. Use `ExportPolicy.NONE` to prevent material from being surfaced to callers.
107
145
  - For gateways, set this provider as the default to keep keys off disk in development and CI.
108
146
 
147
+ ## Want to help?
148
+
149
+ If you want to contribute to swarmauri-sdk, read up on our
150
+ [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
151
+ that will help you get started.
@@ -1,15 +1,42 @@
1
- ![Swamauri Logo](https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png)
1
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
2
+
3
+
4
+ <p align="center">
5
+ <a href="https://pypi.org/project/swarmauri_keyprovider_inmemory/">
6
+ <img src="https://img.shields.io/pypi/dm/swarmauri_keyprovider_inmemory" alt="PyPI - Downloads"/></a>
7
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_inmemory/">
8
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_inmemory.svg"/></a>
9
+ <a href="https://pypi.org/project/swarmauri_keyprovider_inmemory/">
10
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri_keyprovider_inmemory" alt="PyPI - Python Version"/></a>
11
+ <a href="https://pypi.org/project/swarmauri_keyprovider_inmemory/">
12
+ <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_inmemory" alt="PyPI - License"/></a>
13
+ <a href="https://pypi.org/project/swarmauri_keyprovider_inmemory/">
14
+ <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_inmemory?label=swarmauri_keyprovider_inmemory&color=green" alt="PyPI - swarmauri_keyprovider_inmemory"/></a>
15
+ </p>
16
+
17
+ ---
2
18
 
3
19
  # Swarmauri In‑Memory Key Provider
4
20
 
5
- Volatile, in‑memory key provider for Swarmauri. All key material is kept strictly in process memory (no disk writes). Ideal for testing, CI, and ephemeral gateways.
21
+ Volatile, in‑memory key provider for Swarmauri. All key material is kept strictly in process memory (no disk writes). Ideal for testing, CI, and ephemeral gateways where persistence is not desired. Not intended for long‑term or production storage of secrets.
6
22
 
7
23
  ## Installation
8
24
 
25
+ Install the package with your preferred Python tooling:
26
+
9
27
  ```bash
10
28
  pip install swarmauri_keyprovider_inmemory
11
29
  ```
12
30
 
31
+ ```bash
32
+ poetry add swarmauri_keyprovider_inmemory
33
+ ```
34
+
35
+ ```bash
36
+ pip install uv
37
+ uv pip install swarmauri_keyprovider_inmemory
38
+ ```
39
+
13
40
  ## Usage
14
41
 
15
42
  Create and manage symmetric (or opaque/asymmetric placeholder) keys entirely in memory. The snippet below creates a new symmetric key and returns a `KeyRef` with material present when allowed by the export policy.
@@ -17,7 +44,7 @@ Create and manage symmetric (or opaque/asymmetric placeholder) keys entirely in
17
44
  ```python
18
45
  import asyncio
19
46
  from swarmauri_keyprovider_inmemory import InMemoryKeyProvider
20
- from swarmauri_core.keys.types import (
47
+ from swarmauri_core.key_providers.types import (
21
48
  KeySpec,
22
49
  KeyClass,
23
50
  KeyAlg, # optional, not enforced by the provider
@@ -32,7 +59,7 @@ async def main() -> None:
32
59
  # Create a symmetric key kept only in memory
33
60
  spec = KeySpec(
34
61
  klass=KeyClass.symmetric,
35
- alg=KeyAlg.AES256, # optional hint – not strictly enforced
62
+ alg=KeyAlg.AES256_GCM, # optional hint – not strictly enforced
36
63
  uses=(KeyUse.ENCRYPT, KeyUse.DECRYPT),
37
64
  export_policy=ExportPolicy.SECRET_WHEN_ALLOWED, # material may be present
38
65
  label="session-key",
@@ -80,7 +107,19 @@ asyncio.run(main())
80
107
  - No persistence: data is lost when the process exits
81
108
  - Not supported: JWK/JWKS export (will raise `NotImplementedError`)
82
109
 
110
+ ## Security Considerations
111
+
112
+ - Keys exist only for the lifetime of the Python process; restarting drops all material.
113
+ - No hardware isolation or disk persistence is provided.
114
+ - Use only for development, CI, or other ephemeral scenarios.
115
+
83
116
  ## Notes
84
117
 
85
118
  - Exported `KeyRef.material` presence depends on the `ExportPolicy`. Use `ExportPolicy.NONE` to prevent material from being surfaced to callers.
86
119
  - For gateways, set this provider as the default to keep keys off disk in development and CI.
120
+
121
+ ## Want to help?
122
+
123
+ If you want to contribute to swarmauri-sdk, read up on our
124
+ [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
125
+ that will help you get started.
@@ -1,11 +1,11 @@
1
1
  [project]
2
2
  name = "swarmauri_keyprovider_inmemory"
3
- version = "0.2.0.dev4"
3
+ version = "0.2.1.dev9"
4
4
  description = "In-memory key provider for Swarmauri"
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
7
7
  requires-python = ">=3.10,<3.13"
8
- authors = [{ name = "Swarmauri", email = "opensource@swarmauri.com" }]
8
+ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
9
9
  classifiers = [
10
10
  "License :: OSI Approved :: Apache Software License",
11
11
  "Natural Language :: English",
@@ -16,11 +16,22 @@ classifiers = [
16
16
  "Development Status :: 3 - Alpha",
17
17
  "Topic :: Security :: Cryptography",
18
18
  "Intended Audience :: Developers",
19
+ "Programming Language :: Python",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
19
22
  ]
20
23
  dependencies = [
21
24
  "swarmauri_core",
22
25
  "swarmauri_base",
23
26
  ]
27
+ keywords = [
28
+ 'swarmauri',
29
+ 'sdk',
30
+ 'standards',
31
+ 'keyprovider',
32
+ 'inmemory',
33
+ 'key-management',
34
+ ]
24
35
 
25
36
  [tool.uv.sources]
26
37
  swarmauri_core = { workspace = true }
@@ -1,3 +1,5 @@
1
+ """In-memory key provider plugin storing keys solely in process memory."""
2
+
1
3
  from __future__ import annotations
2
4
 
3
5
  from typing import Dict, Iterable, Mapping, Optional, Tuple, Literal
@@ -5,21 +7,34 @@ import secrets
5
7
  import hashlib
6
8
  import hmac
7
9
 
8
- from swarmauri_base.keys.KeyProviderBase import KeyProviderBase
10
+ from swarmauri_base.key_providers.KeyProviderBase import KeyProviderBase
9
11
  from swarmauri_core.crypto.types import KeyRef, KeyType, ExportPolicy
10
- from swarmauri_core.keys.types import KeySpec, KeyClass
12
+ from swarmauri_core.key_providers.types import KeySpec, KeyClass
11
13
 
12
14
 
13
15
  class InMemoryKeyProvider(KeyProviderBase):
14
- """Simple in-memory key provider for testing or ephemeral usage."""
16
+ """In-memory key provider for testing or ephemeral environments.
17
+
18
+ Keys are held only in the Python process and disappear when the process
19
+ terminates. This makes the provider suitable for CI pipelines or local
20
+ development where persistence is undesirable.
21
+ """
15
22
 
16
23
  type: Literal["InMemoryKeyProvider"] = "InMemoryKeyProvider"
17
24
 
18
25
  def __init__(self, **kwargs) -> None:
26
+ """Initialize the provider.
27
+
28
+ **kwargs (Any): Additional arguments forwarded to the base class.
29
+ """
19
30
  super().__init__(**kwargs)
20
31
  self._store: Dict[str, Dict[int, KeyRef]] = {}
21
32
 
22
33
  def supports(self) -> Mapping[str, Iterable[str]]:
34
+ """Describe supported key classes, algorithms, and features.
35
+
36
+ RETURNS (Mapping[str, Iterable[str]]): Provider capability mapping.
37
+ """
23
38
  return {
24
39
  "class": ("sym", "asym"),
25
40
  "algs": (),
@@ -27,6 +42,11 @@ class InMemoryKeyProvider(KeyProviderBase):
27
42
  }
28
43
 
29
44
  async def create_key(self, spec: KeySpec) -> KeyRef:
45
+ """Create a new key.
46
+
47
+ spec (KeySpec): Specification for the key to create.
48
+ RETURNS (KeyRef): Reference to the created key.
49
+ """
30
50
  kid = secrets.token_hex(8)
31
51
  version = 1
32
52
  material = secrets.token_bytes(32)
@@ -53,6 +73,13 @@ class InMemoryKeyProvider(KeyProviderBase):
53
73
  *,
54
74
  public: Optional[bytes] = None,
55
75
  ) -> KeyRef:
76
+ """Import existing key material.
77
+
78
+ spec (KeySpec): Specification of the key to import.
79
+ material (bytes): Secret key material.
80
+ public (bytes): Optional public component.
81
+ RETURNS (KeyRef): Reference to the imported key.
82
+ """
56
83
  kid = secrets.token_hex(8)
57
84
  version = 1
58
85
  ref = KeyRef(
@@ -75,6 +102,13 @@ class InMemoryKeyProvider(KeyProviderBase):
75
102
  async def rotate_key(
76
103
  self, kid: str, *, spec_overrides: Optional[dict] = None
77
104
  ) -> KeyRef:
105
+ """Rotate an existing key to a new version.
106
+
107
+ kid (str): Identifier of the key to rotate.
108
+ spec_overrides (dict): Optional overrides for the key spec.
109
+ RETURNS (KeyRef): Reference to the rotated key.
110
+ RAISES (KeyError): If the key identifier is unknown.
111
+ """
78
112
  bucket = self._store.get(kid)
79
113
  if not bucket:
80
114
  raise KeyError(f"Unknown kid: {kid}")
@@ -97,6 +131,12 @@ class InMemoryKeyProvider(KeyProviderBase):
97
131
  return ref
98
132
 
99
133
  async def destroy_key(self, kid: str, version: Optional[int] = None) -> bool:
134
+ """Destroy key versions.
135
+
136
+ kid (str): Key identifier.
137
+ version (int): Specific version to delete. Deletes all if not provided.
138
+ RETURNS (bool): True if a key was removed.
139
+ """
100
140
  bucket = self._store.get(kid)
101
141
  if not bucket:
102
142
  return False
@@ -115,27 +155,63 @@ class InMemoryKeyProvider(KeyProviderBase):
115
155
  *,
116
156
  include_secret: bool = False,
117
157
  ) -> KeyRef:
158
+ """Retrieve a key version.
159
+
160
+ kid (str): Key identifier.
161
+ version (int): Specific version. Defaults to latest.
162
+ include_secret (bool): When False, secret material may be omitted.
163
+ RETURNS (KeyRef): Requested key reference.
164
+ """
118
165
  bucket = self._store[kid]
119
166
  v = version or max(bucket)
120
167
  return bucket[v]
121
168
 
122
169
  async def list_versions(self, kid: str) -> Tuple[int, ...]:
170
+ """List available versions for a key.
171
+
172
+ kid (str): Key identifier.
173
+ RETURNS (Tuple[int, ...]): Sorted tuple of versions.
174
+ RAISES (KeyError): If the key identifier is unknown.
175
+ """
123
176
  bucket = self._store.get(kid)
124
177
  if not bucket:
125
178
  raise KeyError(f"Unknown kid: {kid}")
126
179
  return tuple(sorted(bucket.keys()))
127
180
 
128
181
  async def get_public_jwk(self, kid: str, version: Optional[int] = None) -> dict:
182
+ """Export a public key in JWK format.
183
+
184
+ kid (str): Key identifier.
185
+ version (int): Specific version.
186
+ RAISES (NotImplementedError): JWK export is not supported.
187
+ """
129
188
  raise NotImplementedError("JWK export not supported")
130
189
 
131
190
  async def jwks(self, *, prefix_kids: Optional[str] = None) -> dict:
191
+ """Return all public keys in JWKS format.
192
+
193
+ prefix_kids (str): Optional key ID prefix filter.
194
+ RAISES (NotImplementedError): JWKS export is not supported.
195
+ """
132
196
  raise NotImplementedError("JWKS export not supported")
133
197
 
134
198
  async def random_bytes(self, n: int) -> bytes:
199
+ """Return cryptographically secure random bytes.
200
+
201
+ n (int): Number of bytes to generate.
202
+ RETURNS (bytes): Random byte string.
203
+ """
135
204
  return secrets.token_bytes(n)
136
205
 
137
206
  async def hkdf(self, ikm: bytes, *, salt: bytes, info: bytes, length: int) -> bytes:
138
- """Derive key material using HKDF-SHA256."""
207
+ """Derive key material using HKDF-SHA256.
208
+
209
+ ikm (bytes): Input keying material.
210
+ salt (bytes): Salt value.
211
+ info (bytes): Context-specific information.
212
+ length (int): Desired output length in bytes.
213
+ RETURNS (bytes): Derived key material.
214
+ """
139
215
  prk = hmac.new(salt, ikm, hashlib.sha256).digest()
140
216
  t = b""
141
217
  okm = b""