You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Polywrap](https://polywrap.io/#/) is a developer tool that enables easy integration of Web3 protocols into any application. It makes it possible for applications on any platform, written in any language, to read and write data to Web3 protocols.
3
+
# Polywrap Python Client
4
4
5
-
## Setup for building and testing
6
-
- Requirement: Python ^3.10, Poetry ^1.1.14
7
-
- If you are using a linux system or WSL, which comes with Python3.8, then you will need to upgrade Python3.8 to Python3.10 and also fix the pip and distutil as upgrading to Python3.10 will break them. You may follow [this guide](https://cloudbytes.dev/snippets/upgrade-python-to-latest-version-on-ubuntu-linux) to upgrade.
8
-
- To install poetry follow [this guide](https://python-poetry.org/docs/#installation). If you are on macos then you can install poetry simply with the following homebrew command
5
+
[Polywrap](https://polywrap.io) is a developer tool that enables easy integration of Web3 protocols into any application. It makes it possible for applications on any platform, written in any language, to read and write data to Web3 protocols.
6
+
7
+
8
+
# Working Features
9
+
10
+
This MVP Python client enables the execution of **[WebAssembly](https://en.wikipedia.org/wiki/WebAssembly) Polywrappers***(or just "wrappers")* on a python environment, regardless of what language this wrapper was built in.
11
+
12
+
The client is built following the functionality of the [JavaScript Polywrap Client](https://github.com/polywrap/toolchain), which is currently more robust and battle tested, as it has additional capabilities than this MVP. In the future, the Polywrap DAO will continue improving this Python capabilities to reach feature parity with the JS stack, while building in parallel clients for other languages like Go and Rust.
13
+
14
+
[Here](https://github.com/polywrap/client-test-harness) you can see which features have been implemented on each language, and make the decision of which one to use for your project.
15
+
16
+
17
+
# Getting Started:
18
+
19
+
Have questions or want to get involved? Join our community [Discord](https://discord.polywrap.io) or [open an issue](https://github.com/polywrap/toolchain/issues) on Github.
20
+
21
+
For detailed information about Polywrap and the WRAP standard, visit our [developer documentation](https://docs.polywrap.io/).
- We will be using [Poetry](https://python-poetry.org) for building and testing our packages.
35
+
> If you are using a Linux system or WSL, which comes with Python3.8, then you will need to upgrade from Python3.8 to Python3.10 and also fix the `pip` and `distutil` as upgrading to Python3.10 will break them. You may follow [this guide](https://cloudbytes.dev/snippets/upgrade-python-to-latest-version-on-ubuntu-linux) to upgrade.
36
+
37
+
### `poetry ^1.1.14`
38
+
- To install poetry follow [this guide](https://python-poetry.org/docs/#installation).
39
+
- If you are on MacOS then you can install poetry simply with the following homebrew command
40
+
```
41
+
brew install poetry
42
+
```
43
+
> To make sure you're it's installed properly, run `poetry`. Learn more [here](https://python-poetry.org/docs/)
44
+
45
+
46
+
47
+
# Building and Testing
17
48
18
-
- Each of the package folders consists the pyproject.toml file and the poetry.lock file. In pyproject.toml file, one can find out all the project dependencies and configs related to the package. These files will be utilized by Poetry to install correct dependencies, build, lint and test the package.
49
+
## Poetry
19
50
20
-
- For example, we can install deps, build and test the polywrap-msgpack package using Poetry.
51
+
- We will be using [Poetry](https://python-poetry.org) for building and testing our packages.
52
+
Each of the package folders consists of the `pyproject.toml` file and the `poetry.lock` file. In `pyproject.toml` file, one can find out all the project dependencies and configs related to the package. These files will be utilized by Poetry to install correct dependencies, build, lint and test the package.
53
+
54
+
- For example, we can **install** deps, **build** and **test** the `polywrap-msgpack` package using Poetry.
21
55
22
56
- Install dependencies using Poetry.
23
57
```
24
58
poetry install
25
59
```
26
-
> Make sure your cwd is `polywrap-msgpack` package.
27
-
- As we can see in the pyproject.toml file, we installed [PyTest](https://docs.pytest.org) package. We will be using the same as our testing framework.
28
-
- Now we are ready to build and test the core package using Poetry and PyTest.
29
-
- To build the package run the following command
60
+
> Make sure your cwd is the appropriate module, for example `polywrap-msgpack`, `polywrap-wasm` or `polywrap-client`.
61
+
62
+
## Pytest
63
+
64
+
In order to assure the integrity of the modules Polywrap Python Client uses [pytest 7.1.3](https://docs.pytest.org/en/7.1.x/contents.html) as a testing framework.
65
+
66
+
- As we can see in the `pyproject.toml` files, we installed the [PyTest](https://docs.pytest.org) package. We will be using it as our testing framework.
67
+
- Now we are ready to **build** and **test** the core package using Poetry and PyTest.
68
+
69
+
To build the package run the following command
30
70
```
31
71
poetry build
32
72
```
33
-
- You need to activate the venv with poetry using `poetry shell` command before running any other command
34
-
- We are using tox to run lint and tests easily. You can list all the testenv defined in the
35
-
tox config with following command
73
+
74
+
You need to activate the venv with poetry using the `shell` command before running any other command
75
+
```
76
+
poetry shell
77
+
```
78
+
79
+
Finally, to test your module to execute the test suite:
80
+
```
81
+
poetry run pytest
82
+
```
83
+
84
+
85
+
This last command will run a series of scripts that verify that the specific module of the client is performing as expected in your local machine. The output on your console should look something like this:
86
+
87
+
```
88
+
$ poetry run pytest
89
+
>>
90
+
================================= test session starts =================================
91
+
platform darwin -- Python 3.10.0, pytest-7.1.3, pluggy-1.0.0
You should expect to see the tests passing with a 100% accuracy. To better understand these outputs, read [this quick guide](https://docs.pytest.org/en/7.1.x/how-to/output.html). If any of the functionality fails (marked with an 'F'), or if there are any Warnings raised, you can debug them by running a verbose version of the test suite:
101
+
-`poetry run pytests -v` or `poetry run pytests -vv` for even more detail
102
+
- Reach out to the devs on the [Discord](https://discord.polywrap.io) explaining your situation, and what configuration you're using on your machine.
103
+
104
+
105
+
## TOX
106
+
We are using [`tox`](https://tox.wiki/en) to run lint and tests even more easily. Below are some basic commands to get you running.
107
+
108
+
### List all the testenv defined in the tox config
36
109
```
37
110
tox -a
38
111
```
39
-
- To run tests using tox simply run `tox`
40
-
- You can run linters with the `tox -e lint` and check type with `tox -e typecheck`. By running `tox -e secure`, you can find security vulnerability if any.
41
-
- While developing, you can run `tox -e dev` and apply lint fixes and style formatting.
42
-
- As we see the mentioned tests passing, we are ready to update and test the package.
112
+
### Run tests
113
+
```
114
+
tox
115
+
```
116
+
### Linting
117
+
```
118
+
tox -e lint
119
+
```
120
+
### Check types
121
+
```
122
+
tox -e typecheck
123
+
```
43
124
44
-
## For VSCode users
45
-
If you use VSCode, open this setup using the workspace file python-monorepo.code-workspace:
125
+
### Find security vulnerabilities, if any
126
+
```
127
+
tox -e secure
128
+
```
46
129
130
+
### Dev environment
131
+
Use this command to only apply lint fixes and style formatting.
47
132
```
48
-
File -> Open Workspace from File...
133
+
tox -e dev
49
134
```
50
135
51
-
Each folder is now a project to VSCode. For the Python virtual environments to be picked up automatically, you need to create .vscode/settings.json file in each folder, pointing to the in-project virtual environment created by the poetry.
136
+
- After running these commands we should see all the tests passing and commands executing successfully, which means that we are ready to update and test the package.
137
+
- To create your own tox scripts, modify the `tox.ini` file in the respective module.
138
+
139
+
## VSCode users: Improved dev experience
140
+
If you use VSCode, we have prepared a pre-configured workspace that improves your dev experience. So when you open VScode, set up the workspace file `python-monorepo.code-workspace` by going to:
52
141
53
-
You can easily find the correct virtual env by running following command in the package for which you want to find it
54
142
```
55
-
poetry shell
143
+
File -> Open Workspace from File...
56
144
```
145
+

146
+
147
+
Each folder is now a project to VSCode. This action does not change the underlying code, but facilitates the development process. So our file directory should look like this now:
148
+
149
+

57
150
58
-
Once you get the virtual env, you need to create the following `settings.json` file under the .vscode folder of the given package.
59
-
Ex: in case of polywrap-client package, it would be under:
151
+
> Note: You might have to do this step again next time you close and open VS code!
152
+
153
+
### Picking up the virtual environments automatically
154
+
We will need to create a `.vscode/settings.json` file in each module's folder, pointing to the in-project virtual environment created by the poetry.
155
+
156
+
- You can easily find the path to the virtual env by running following command in the package for which you want to find it for:
60
157
```
61
-
polywrap-client -> .vscode -> settings.json
158
+
poetry shell
62
159
```
63
160
64
-
Here's the `settings.json` file we are using for configuring the vscode:
161
+
- Once you get the path virtual env, you need to create the following `settings.json` file under the `.vscode/` folder of the given package. For example, in case of `polywrap-client` package, it would be under
162
+
`./polywrap-client/.vscode/settings.json`
163
+
164
+
165
+
Here's the structure `settings.json` file we are using for configuring the vscode. Make sure you update your virtual env path you got from poetry as the `python.defaultInterpreterPath` argument:
65
166
```json
66
167
{
67
168
"python.formatting.provider": "black",
@@ -70,6 +171,71 @@ Here's the `settings.json` file we are using for configuring the vscode:
You need to put your virtual env path you got from the poetry under: `python.defaultInterpreterPath`
74
174
75
-
Once you configure this you should be good to go.
175
+
Keep in mind that these venv paths will vary for each module you run `poetry shell` on. Once you configure these `setting.json` files correctly on each module you should be good to go!
176
+
177
+
178
+
# What WASM wrappers can you execute today?
179
+
180
+
Check these resources to browse a variety available wrappers, for DeFi, decentralised storage, and other development utilites:
Calling a function of a wrapper from the python client is as simple as creating a file in the `TODO (?polywrap-client)` directory, importing the `PolywrapClient`, calling the `Uri` where the WASM wrapper is hosted, and specifying any required `arguments`.
188
+
189
+
Here is an example which takes in a message as a string and returns it.
190
+
191
+
```python
192
+
# hello_world.py
193
+
from polywrap_client import PolywrapClient
194
+
from polywrap_core import Uri, InvokerOptions
195
+
196
+
asyncdefecho_message(message: str):
197
+
198
+
# Instantiate the client
199
+
client = PolywrapClient()
200
+
201
+
# Load the WebAssembly wrapper through a URI that points to local file system
202
+
uri = Uri('wrap://ens/rinkeby/helloworld.dev.polywrap.eth')
By creating tests you can quickly experiment with the Polywrap Client and its growing set of wrappers. Since Pytest is already set up on the repo, go to the `polywrap-client\tests\` directory, and take a look at how some of the functions are built. You can use similar patterns to mod your own apps and build new prototypes with more complex functionality.
224
+
225
+
Here's a good guide to learn about [building tests with Pytest](https://realpython.com/pytest-python-testing/)
226
+
227
+
# Contributing
228
+
229
+
The Polywrap project is completely open-source and we welcome contributors of all levels. Learn more about how you can contribute [here](https://github.com/polywrap/toolchain#contributing).
230
+
231
+
# Contact Us:
232
+
233
+
[Join our discord](https://discord.polywrap.io) and ask your questions right away!
0 commit comments