Skip to content

Commit b0e9ac6

Browse files
authored
Merge pull request #235 from polywrap/dev
prep 0.1.0b5 | /workflows/cd
2 parents 6b3fff0 + 2249ed3 commit b0e9ac6

File tree

18 files changed

+595
-230
lines changed

18 files changed

+595
-230
lines changed

CONTRIBUTING.md

Lines changed: 539 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 40 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -2,240 +2,66 @@
22

33
# Polywrap Python Client
44

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.
5+
[Polywrap](https://polywrap.io) is a protocol for building and executing composable wrappers for any web3 protocol. Polywrap Python Client is a Python library that allows you to easily execute Polywrap Wrappers.
66

7+
## Quickstart
78

8-
# Working Features
9+
### Import necessary packages
910

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/).
22-
23-
## Pre-requisites
24-
25-
### Clone the repo.
26-
```
27-
git clone https://github.com/polywrap/python-client
28-
```
29-
30-
### `python ˆ3.10`
31-
- Make sure you're running the correct version of python by running:
32-
```
33-
python3 --version
34-
```
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
48-
49-
## Poetry
50-
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.
55-
56-
- Install dependencies using Poetry.
57-
```
58-
poetry install
59-
```
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
70-
```
71-
poetry build
72-
```
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
92-
rootdir: /Users/polywrap/pycode/polywrap/toolchain/packages/py, configfile: pytest.ini
93-
collected 26 items
94-
95-
tests/test_msgpack.py ........................ [100%]
96-
```
97-
98-
### Debugging with Pytest:
99-
100-
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
109-
```
110-
tox -a
111-
```
112-
### Run tests
113-
```
114-
tox
115-
```
116-
### Linting
117-
```
118-
tox -e lint
119-
```
120-
### Check types
121-
```
122-
tox -e typecheck
123-
```
124-
125-
### Find security vulnerabilities, if any
126-
```
127-
tox -e secure
128-
```
129-
130-
### Dev environment
131-
Use this command to only apply lint fixes and style formatting.
132-
```
133-
tox -e dev
134-
```
135-
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:
141-
142-
```
143-
File -> Open Workspace from File...
144-
```
145-
![File -> Open Workspace from File](misc/VScode_OpenWorkspaceFromFile.png)
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-
![all modules have their respective folder, along with a root folder](misc/VScode_workspace.png)
150-
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:
157-
```
158-
poetry shell
11+
```python
12+
from polywrap_core import Uri, ClientConfig
13+
from polywrap_client import PolywrapClient
14+
from polywrap_client_config_builder import PolywrapClientConfigBuilder
15+
from polywrap_sys_config_bundle import sys_bundle
16+
from polywrap_web3_config_bundle import web3_bundle
15917
```
16018

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:
166-
```json
167-
{
168-
"python.formatting.provider": "black",
169-
"python.languageServer": "Pylance",
170-
"python.analysis.typeCheckingMode": "strict",
171-
"python.defaultInterpreterPath": "/Users/polywrap/Library/Caches/pypoetry/virtualenvs/polywrap-client-abcdef-py3.10"
172-
}
19+
### Configure and Instantiate the client
20+
```python
21+
builder = (
22+
PolywrapClientConfigBuilder()
23+
.add_bundle(sys_bundle)
24+
.add_bundle(web3_bundle)
25+
)
26+
config = builder.build()
27+
client = PolywrapClient(config)
17328
```
17429

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:
181-
182-
- [Wrappers.io](https://wrappers.io/)
183-
- [Polywrap Integrations Repository](https://github.com/polywrap/integrations)
184-
185-
# Example call
186-
187-
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.
30+
### Invoke a wrapper
19031

19132
```python
192-
# hello_world.py
193-
from polywrap_client import PolywrapClient
194-
from polywrap_core import Uri, InvokerOptions
195-
196-
async def echo_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')
203-
204-
args = {"arg": message }
205-
206-
# Configure the client
207-
options = InvokerOptions(
208-
uri=uri, method="simpleMethod", args=args, encode_result=False
209-
)
210-
211-
# Invoke the wrapper
212-
result = await client.invoke(options)
213-
214-
return result.result
215-
216-
if __name__ == "__main__":
217-
return echo_message('hello polywrap!')
33+
uri = Uri.from_str(
34+
'wrapscan.io/polywrap/ipfs-http-client'
35+
)
36+
args = {
37+
"cid": "QmZ4d7KWCtH3xfWFwcdRXEkjZJdYNwonrCwUckGF1gRAH9",
38+
"ipfsProvider": "https://ipfs.io",
39+
}
40+
result = client.invoke(uri=uri, method="cat", args=args, encode_result=False)
41+
assert result.startswith(b"<svg")
21842
```
21943

44+
## Working Features
22045

221-
## Creating your own tests for the client
46+
[Here](https://github.com/polywrap/client-test-harness) you can see which features have been implemented on each language client, and make the decision of which one to use for your project.
22247

223-
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.
48+
## Feedback & Contributions
49+
Bugs and feature requests can be made via [GitHub issues](https://github.com/polywrap/python-client/issues). Be aware that these issues are not private, so take care when providing output to make sure you are not disclosing any personal informations.
22450

225-
Here's a good guide to learn about [building tests with Pytest](https://realpython.com/pytest-python-testing/)
51+
[Pull requests](https://github.com/polywrap/python-client/pulls) are also welcome via git.
22652

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).
53+
New contributors should read the [contributor guide](./CONTRIBUTING.md) to get started.
54+
Folk who already have experience contributing to open source projects may not need the full guide but should still use the pull request checklist to make things easy for everyone.
55+
Polywrap Python Client contributors are asked to adhere to the [Python Community Code of Conduct](https://www.python.org/psf/conduct/).
23056

23157
# Contact Us:
23258

23359
[Join our discord](https://discord.polywrap.io) and ask your questions right away!
23460

235-
23661
# Resources
23762

23863
- [Polywrap Documentation](https://docs.polywrap.io)
239-
- [Polywrap Integrations Repository](https://github.com/polywrap/integrations)
240-
- [Running operations concurrently with python's asyncio](https://realpython.com/async-io-python/#the-10000-foot-view-of-async-io)
241-
- [Intro Video](TODO)
64+
- [Python Client Documentation](https://polywrap-client.rtfd.io)
65+
- [Client Readiness](https://github.com/polywrap/client-readiness)
66+
- [Discover Wrappers](https://wrapscan.io)
67+
- [Polywrap Discord](https://discord.polywrap.io)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0b4
1+
0.1.0b5
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0b4
1+
0.1.0b5
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0b4
1+
0.1.0b5
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0b4
1+
0.1.0b5
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0b4
1+
0.1.0b5
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0b4
1+
0.1.0b5
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0b4
1+
0.1.0b5

packages/polywrap-client/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0b4
1+
0.1.0b5

0 commit comments

Comments
 (0)