Skip to content

Commit b85169d

Browse files
authored
Merge pull request #115 from polywrap/nk/readme
feat: add readme for every packages
2 parents 95f0fa7 + acf7903 commit b85169d

File tree

10 files changed

+256
-298
lines changed

10 files changed

+256
-298
lines changed
Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,64 @@
1+
# polywrap-client-config-builder
12

2-
# Polywrap Python Client
3-
## This object allows you to build proper Polywrapt ClientConfig objects
3+
A utility class for building the PolywrapClient config.
44

5-
These objects are needed to configure your python client's wrappers, pluggins, env variables, resolvers and interfaces.
5+
Supports building configs using method chaining or imperatively.
66

7-
Look at [this file](./polywrap_client_config_builder/client_config_builder.py) to detail all of its functionality
8-
And at [tests](./tests/test_client_config_builder.py)
7+
## Quickstart
98

10-
---
9+
### Initialize
1110

12-
The current implementation uses the `ClientConfig` as a dataclass to later create an Abstract Base Class of a `BaseClientConfigBuilder` which defines more clearly the functions of the module, like add_envs, set_resolvers, remove_wrappers, and so on.
11+
Initialize a ClientConfigBuilder using the constructor
1312

14-
This `BaseClientConfigBuilder` is later used in the class `ClientConfigBuilder` which only implements the build method, for now, and inherits all the abstract methods of the `BaseClientConfigBuilder`.
13+
```python
14+
# start with a blank slate (typical usage)
15+
builder = ClientConfigBuilder()
16+
```
17+
18+
### Configure
19+
20+
Add client configuration with add, or flexibly mix and match builder configuration methods to add and remove configuration items.
21+
22+
```python
23+
# add multiple items to the configuration using the catch-all `add` method
24+
builder.add(
25+
BuilderConfig(
26+
envs={},
27+
interfaces={},
28+
redirects={},
29+
wrappers={},
30+
packages={},
31+
resolvers=[]
32+
)
33+
)
34+
35+
// add or remove items by chaining method calls
36+
builder
37+
.add_package("wrap://plugin/package", test_plugin({}))
38+
.remove_package("wrap://plugin/package")
39+
.add_packages(
40+
{
41+
"wrap://plugin/http": http_plugin({}),
42+
"wrap://plugin/filesystem": file_system_plugin({}),
43+
}
44+
)
45+
```
46+
47+
### Build
48+
49+
Finally, build a ClientConfig to pass to the PolywrapClient constructor.
50+
51+
```python
52+
# accepted by the PolywrapClient
53+
config = builder.build()
54+
55+
# build with a custom cache
56+
config = builder.build({
57+
wrapperCache: WrapperCache(),
58+
})
59+
60+
# or build with a custom resolver
61+
coreClientConfig = builder.build({
62+
resolver: RecursiveResolver(...),
63+
})
64+
```

packages/polywrap-client/README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
1-
TODO
1+
# polywrap-client
2+
3+
Python implementation of the polywrap client.
4+
5+
## Usage
6+
7+
### Configure and Instantiate
8+
9+
Use the `polywrap-uri-resolvers` package to configure resolver and build config for the client.
10+
11+
```python
12+
from polywrap_uri_resolvers import FsUriResolver, SimpleFileReader
13+
14+
config = ClientConfig(
15+
resolver=FsUriResolver(file_reader=SimpleFileReader())
16+
)
17+
18+
client = PolywrapClient(config)
19+
```
20+
21+
### Invoke
22+
23+
Invoke a wrapper.
24+
25+
```python
26+
uri = Uri.from_str(
27+
'fs/<path to wrapper>' # Example uses simple math wrapper
28+
)
29+
args = {
30+
"arg1": "123", # The base number
31+
"obj": {
32+
"prop1": "1000", # multiply the base number by this factor
33+
},
34+
}
35+
options: InvokerOptions[UriPackageOrWrapper] = InvokerOptions(
36+
uri=uri, method="method", args=args, encode_result=False
37+
)
38+
result = await client.invoke(options)
39+
assert result == "123000"
40+
```

packages/polywrap-core/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
TODO
1+
# polywrap-core
2+
3+
A Python implementation of the WRAP standard, including all fundamental types & algorithms.

packages/polywrap-core/poetry.lock

Lines changed: 28 additions & 283 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/polywrap-core/pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ authors = ["Cesar <cesar@polywrap.io>", "Niraj <niraj@polywrap.io>"]
1010

1111
[tool.poetry.dependencies]
1212
python = "^3.10"
13-
gql = "3.4.0"
14-
graphql-core = "^3.2.1"
1513
polywrap-manifest = { path = "../polywrap-manifest", develop = true }
1614
polywrap-msgpack = { path = "../polywrap-msgpack", develop = true }
17-
pydantic = "^1.10.2"
1815

1916
[tool.poetry.dev-dependencies]
2017
pytest = "^7.1.2"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# polywrap-manifest
2+
3+
Python implementation of the WRAP manifest schema at https://github.com/polywrap/wrap
4+
5+
## Usage
6+
7+
### Deserialize WRAP manifest
8+
9+
```python
10+
from polywrap_manifest import deserialize_wrap_manifest, WrapManifest_0_1
11+
12+
with open("<path to WRAP package>/wrap.info", "rb") as f:
13+
raw_manifest = f.read()
14+
15+
manifest = deserialize_wrap_manifest(raw_manifest)
16+
assert isinstance(manifest, WrapManifest_0_1)
17+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# polywrap-msgpack
2+
3+
Python implementation of the WRAP MsgPack encoding standard.
4+
5+
## Usage
6+
7+
### Encoding-Decoding Native types and objects
8+
9+
```python
10+
from polywrap_msgpack import msgpack_decode, msgpack_encode
11+
12+
dictionary = {
13+
"foo": 5,
14+
"bar": [True, False],
15+
"baz": {
16+
"prop": "value"
17+
}
18+
}
19+
20+
encoded = msgpack_encode(dictionary)
21+
decoded = msgpack_decode(encoded)
22+
23+
assert dictionary == decoded
24+
```
25+
26+
### Encoding-Decoding Extension types
27+
28+
```python
29+
from polywrap_msgpack import msgpack_decode, msgpack_encode, GenericMap
30+
31+
counter: GenericMap[str, int] = GenericMap({
32+
"a": 3,
33+
"b": 2,
34+
"c": 5
35+
})
36+
37+
encoded = msgpack_encode(counter)
38+
decoded = msgpack_decode(encoded)
39+
40+
assert counter == decoded
41+
```

packages/polywrap-plugin/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# polywrap-wasm
2+
3+
Python implementation of the plugin wrapper runtime.
4+
5+
## Usage
6+
7+
### Invoke Plugin Wrapper
8+
9+
```python
10+
from typing import Any, Dict, List, Union, Optional
11+
from polywrap_manifest import AnyWrapManifest
12+
from polywrap_plugin import PluginModule
13+
from polywrap_core import Invoker, Uri, InvokerOptions, UriPackageOrWrapper, Env
14+
15+
class GreetingModule(PluginModule[None]):
16+
def __init__(self, config: None):
17+
super().__init__(config)
18+
19+
def greeting(self, args: Dict[str, Any], client: Invoker[UriPackageOrWrapper], env: Optional[Env] = None):
20+
return f"Greetings from: {args['name']}"
21+
22+
manifest = cast(AnyWrapManifest, {})
23+
wrapper = PluginWrapper(greeting_module, manifest)
24+
args = {
25+
"name": "Joe"
26+
}
27+
options: InvokeOptions[UriPackageOrWrapper] = InvokeOptions(
28+
uri=Uri.from_str("ens/greeting.eth"),
29+
method="greeting",
30+
args=args
31+
)
32+
invoker: Invoker = ...
33+
34+
result = await wrapper.invoke(options, invoker)
35+
assert result, "Greetings from: Joe"
36+
```
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
TODO
1+
# polywrap-uri-resolvers
2+
3+
URI resolvers to customize URI resolution in the Polywrap Client.
4+

packages/polywrap-wasm/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
TODO
1+
# polywrap-wasm
2+
3+
Python implementation of the Wasm wrapper runtime.
4+
5+
## Usage
6+
7+
### Invoke Wasm Wrapper
8+
9+
```python
10+
from typing import cast
11+
from polywrap_manifest import AnyWrapManifest
12+
from polywrap_core import FileReader, Invoker
13+
from polywrap_wasm import WasmWrapper
14+
15+
file_reader: FileReader = ... # any valid file_reader, pass NotImplemented for mocking
16+
wasm_module: bytes = bytes("<wrapper wasm module bytes read from file or http>")
17+
wrap_manifest: AnyWrapManifest = ...
18+
wrapper = WasmWrapper(file_reader, wasm_module, wrap_manifest)
19+
invoker: Invoker = ... # any valid invoker, mostly PolywrapClient
20+
21+
message = "hey"
22+
args = {"arg": message}
23+
options: InvokeOptions[UriPackageOrWrapper] = InvokeOptions(
24+
uri=Uri.from_str("fs/./build"), method="simpleMethod", args=args
25+
)
26+
result = await wrapper.invoke(options, invoker)
27+
assert result.encoded is True
28+
assert msgpack_decode(cast(bytes, result.result)) == message
29+
```

0 commit comments

Comments
 (0)