docs(blog): running python with WebAssembly part 1#823
Conversation
|
@coderabbitai review |
WalkthroughThe new documentation introduces a guide for integrating a Python runtime with the metatype ecosystem using WebAssembly (WASI). It covers the motivations for this integration, technical requirements, and implementation strategies, including the use of Docker and WebAssembly for platform independence. The guide addresses challenges such as security and user-friendliness, and provides a Rust code snippet for initializing the Python virtual machine within the WASI context. Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant WASI
participant PythonVM
participant Docker
Developer->>Docker: Set up environment
Docker->>WASI: Initialize WebAssembly
WASI->>PythonVM: Load Python runtime
PythonVM-->>WASI: Ready to execute scripts
Developer->>PythonVM: Execute Python script
PythonVM-->>Developer: Return results
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (3)
website/blog/2024-08-26-how-we-run-python-using-webassembly/index.mdx (3)
10-18: Fix typographical issue.Add a comma before "and" in line 16.
- which, as you may know, is very popular and its standard library can be quite resourceful for this type of use case. + which, as you may know, is very popular, and its standard library can be quite resourceful for this type of use case.Tools
LanguageTool
[uncategorized] ~16-~16: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ... which, as you may know, is very popular and its standard library can be quite resou...(COMMA_COMPOUND_SENTENCE_2)
21-27: Fix typographical issue.Correct the typo in line 27: "writting" should be "writing".
- 3. **User-friendliness**: writting a function in one langauge should be as near identical as writting one in another + 3. **User-friendliness**: writing a function in one language should be as near identical as writing one in another
29-37: Fix typographical issues.Correct the issues in lines 29, 31, and 34:
- ## Choosing an approach.. + ## Choosing an approach. - Let's start simple, we want to run python code so what do we need? + Let's start simple, we want to run python code, so what do we need? - We do not want to be platform dependent, but how can we achieve that? + We do not want to be platform-dependent, but how can we achieve that?Tools
LanguageTool
[typographical] ~29-~29: Two consecutive dots
Context: ... one in another ## Choosing an approach.. Let's start simple, we want to run pyt...(DOUBLE_PUNCTUATION)
[uncategorized] ~31-~31: Use a comma before ‘so’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...start simple, we want to run python code so what do we need? * A python runtime We...(COMMA_COMPOUND_SENTENCE_2)
[uncategorized] ~34-~34: This expression is ususally spelled with a hyphen
Context: ... A python runtime We do not want to be platform dependent, but how can we achieve that? * docker ...(SPECIFIC_HYPHEN)
zifeo
left a comment
There was a problem hiding this comment.
Maybe uppercasing the tech name? e.g. Metatype, Deno?
Yohe-Am
left a comment
There was a problem hiding this comment.
I like what's there so far but I have some comments. Willing to address them myself if you don't mind. Might have to rework the structure to better introduce the second section.
@Yohe-Am feel free to do so, I sort of wrote it in a way that it can be merged as is. |
Signed-off-by: michael-0acf4 <afmichael73@gmail.com>
Signed-off-by: michael-0acf4 <afmichael73@gmail.com>
2751c00 to
bd05016
Compare
|
@coderabbitai review |
There was a problem hiding this comment.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (7)
docs/metatype.dev/vale/config/vocabularies/Metatype/accept.txt (1)
39-39: Fix the spelling of "GitHub".The term "GitHub" is typically spelled with a capital "H".
Apply this diff to fix the spelling:
-Github +GitHubdocs/metatype.dev/blog/2024-08-26-python-on-webassembly/index.mdx (6)
5-24: Fix the grammatical and punctuation issues.Please address the following:
- Line 10: Add a comma after "AWS Lambda is one such example" to separate the independent clauses.
- Line 10: Replace "are" with "is" in "FaaS as a whole are a popular implementation".
- Line 20: Add a comma after "Implementing the
DenoRuntimewas a very straightforward affair".- Line 23: Add a comma after "dominance of JavaScript in the serverless market".
- Line 25: Add a comma after "Another very popular language is Python".
Tools
LanguageTool
[uncategorized] ~10-~10: Possible missing comma found.
Context: ...d configuration. AWS Lambda is one such example and FaaS as a whole are a popular imple...(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~10-~10: The verb “are” doesn’t seem to fit in this context, “is” is probably more formally correct.
Context: ...is one such example and FaaS as a whole are a popular implementation of the serverl...(AI_HYDRA_LEO_CPT_ARE_IS)
[uncategorized] ~16-~16: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... typegraphs on a single deployed cluster but we're still in the kitchen on a hosted ...(COMMA_COMPOUND_SENTENCE)
[uncategorized] ~20-~20: Possible missing comma found.
Context: ...DenoRuntime` was a very straightforward affair as the Typegate (the orchestrator at th...(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~23-~23: Possible missing comma found.
Context: ...minance of JavaScript in the serverless market though it doesn't hurt that it's also t...(AI_HYDRA_LEO_MISSING_COMMA)
28-36: Minor punctuation improvements.Consider the following:
- Line 30: Add a comma before "but" in "There are a number of Python runtimes available but a set of extra factors limit what we can achieve."
- Line 35: Add a comma after "parts of the app running on the Typegate" to separate the independent clause.
Tools
LanguageTool
[uncategorized] ~30-~30: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...re a number of Python runtimes available but a set of extra factors limit what we ca...(COMMA_COMPOUND_SENTENCE_2)
[uncategorized] ~35-~35: Possible missing comma found.
Context: ...o other parts of the app running on the Typegate like being able to invoke other functio...(AI_HYDRA_LEO_MISSING_COMMA)
37-51: Improve wording and punctuation.Please consider the following changes:
- Line 39: Replace "multi-processing" with "multiprocessing".
- Line 39: Consider replacing "readily apparent" with a shorter alternative to avoid wordiness.
- Line 42: Add a comma after "The PyO3 project which provide Rust bindings to different Python runtimes like CPython and PyPy."
- Line 43: Add a comma before "but" and fix verb form in "It'd not only allow us to run Python code in-process but it also provide an easy way to expose the functions written in Rust to Python and vice-versa." It should be "...but it also provides...".
- Line 48: Replace "a executable" with "an executable".
Tools
LanguageTool
[misspelling] ~39-~39: This word is normally spelled as one.
Context: ...nk Linux containers. This fact renders multi-processing, one of the readily apparent approaches...(EN_COMPOUNDS_MULTI_PROCESSING)
[style] ~39-~39: ‘readily apparent’ might be wordy. Consider a shorter alternative.
Context: ...ct renders multi-processing, one of the readily apparent approaches, undesirable as it would req...(EN_WORDINESS_PREMIUM_READILY_APPARENT)
[uncategorized] ~42-~42: Possible missing comma found.
Context: ...lf here is the PyO3 project which provide Rust bindings to differen...(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~43-~43: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...y allow us to run Python code in-process but it also provide an easy way to expose t...(COMMA_COMPOUND_SENTENCE)
[grammar] ~43-~43: After ‘it’, use the third-person verb form “provides”.
Context: ... run Python code in-process but it also provide an easy way to expose the functions wri...(IT_VBZ)
[grammar] ~43-~43: The expression “vice versa” is spelled without hyphens.
Context: ...functions written in Rust to Python and vice-versa. A good solution for the bidirectional...(VICE_VERSA)
[style] ~44-~44: Consider using a different adjective in this context to strengthen your wording.
Context: ...en in Rust to Python and vice-versa. A good solution for the bidirectional communic...(GOOD_ALTERNATIVE)
[misspelling] ~48-~48: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...ture. WebAssembly or Wasm for short is a executable bytecode format that origina...(EN_A_VS_AN)
52-67: Improve grammar, punctuation and wording.Please address the following:
- Line 54: Add a comma after "but also" in "but also, in it's latest iteration extends to any custom host defined functionality."
- Line 60: Add a comma after "preview1)" implementation was supported by most runtimes".
- Line 60: Consider replacing "In order to" with a shorter alternative to avoid wordiness.
- Line 63: Fix typo: "An based native API" should be "A based native API".
- Line 65: Replace "ticks of" with "ticks off".
- Line 65: Remove redundant "of" in "ticks of all of the sandboxing".
Tools
LanguageTool
[uncategorized] ~54-~54: Possible missing comma found.
Context: ...and networking but also, in it's latest iteration extends to any custom host defined func...(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~60-~60: Possible missing comma found.
Context: ...)" implementation was supported by most runtimes which meant having to rely on simple C ...(AI_HYDRA_LEO_MISSING_COMMA)
[style] ~60-~60: Consider a shorter alternative to avoid wordiness.
Context: ...ns for intra-process communication. In order to make this work easier, we elected to br...(IN_ORDER_TO_PREMIUM)
[misspelling] ~63-~63: Use “A” instead of ‘An’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...e python interpreter wrapped in a PyO3. An based native API. \ An assembly that ac...(EN_A_VS_AN)
[uncategorized] ~65-~65: “of” seems less likely than “off” (as in: go/turn off, off the coast).
Context: ...asmedge.org/) in this case, which ticks of all of the sandboxing and security requ...(AI_HYDRA_LEO_CP_OF_OFF)
[style] ~65-~65: Consider removing “of” to be more concise
Context: ...edge.org/) in this case, which ticks of all of the sandboxing and security requirements. T...(ALL_OF_THE)
70-109: Minor grammar improvements.Consider the following changes:
- Line 72: Add "to" in "we'll need to find a way to load
libpythonat runtime." It should be "we'll need to find a way to loadlibpythonat runtime."- Line 81: Add a comma before "but" in "This approach turned out to be quite hacky though and after encountering several issues, we ultimately decided to go with preopens."
Tools
LanguageTool
[uncategorized] ~72-~72: Possible missing preposition found.
Context: ...ython runtime, we'll need to find a way loadlibpythonat runtime. Thankfully, Was...(AI_HYDRA_LEO_MISSING_TO)
[uncategorized] ~72-~72: The preposition ‘to’ seems more likely in this position.
Context: ...'ll need to find a way loadlibpythonat runtime. Thankfully, Wasm does support ...(AI_HYDRA_LEO_REPLACE_AT_TO)
[uncategorized] ~81-~81: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...file on disk before running the instance but it was an acceptable solution. We also ...(COMMA_COMPOUND_SENTENCE)
111-223: Final improvements.Please consider the following changes:
- Line 117: Replace "it should possible" with "it should be possible".
- Line 120: Add a hyphen in "new found WASI powers". It should be "new-found WASI powers".
- Line 120: Fix subject-verb agreement in "This lead us to implement..." It should be "This led us to..."
- Line 122: Replace "it's" with "its" in "reproduced down below in it's entirety."
- Line 193: Add a comma after "boundary though" in "doing a bit more than acting as a boundary though."
- Line 196: Replace "anyways" with "anyway".
- Line 199: Add "a" in "It has code generation suite". It should be "It has a code generation suite".
- Line 203: Add a comma after "for the resulting component" in "for the resulting component baking the
libpythonobject code".- Line 206: Add a comma before "but" in "interface on the Typegate but this implementation".
- Line 213: Remove redundant "only" in "Sure, you only pay this cost only the first time".
- Line 214: Add "a" in "10 second is unacceptable in system". It should be "10 second is unacceptable in a system".
- Line 217: Add a comma after "here specifically" in "feature comes to the rescue here specifically their [AOT compilation]".
- Line 219: Add a comma after "the JIT cost" in "This eliminates the JIT cost but the nature".
- Line 219: Replace "safe-guards" with "safeguards".
- Line 220: Add a comma after "Typegate binary itself" in "compressing it) in the Typegate binary itself ensuring minimal".
- Line 223: Add a comma before "and" in "Hopefully, all details were clear enough and please direct any feedback".
Tools
LanguageTool
[style] ~114-~114: Consider an alternative for the overused word “exactly”.
Context: ...re always ready to get rid of. This was exactly what we did after the Bytecode Alliance...(EXACTLY_PRECISELY)
[grammar] ~117-~117: It looks like a verb is missing here. Did you mean “be possible”?
Context: ...new capabilities suggest that it should possible to replace our PyO3 based glue code wit...(MISSING_BE_JJ)
[misspelling] ~120-~120: This word is normally spelled with a hyphen.
Context: ...yer. Let's see how. We first used the new found WASI powers to implement support for Wa...(EN_COMPOUNDS_NEW_FOUND)
[uncategorized] ~120-~120: This expression is usually spelled with a hyphen.
Context: ...nd WASI powers to implement support for Wasm based functions through the [WasmRuntime](/...(BASED_HYPHEN)
[grammar] ~120-~120: Possible subject-verb agreement error detected.
Context: ...ntime](/docs/reference/runtimes/wasm). This lead us to implement the [wit_wire`](https:...(THIS_THAT_AGR)
[uncategorized] ~121-~121: This expression is usually spelled with a hyphen.
Context: ...rc/wit/wit-wire.wit) protocol, a simple JSON based WIT interface that'd be used by any was...(BASED_HYPHEN)
[uncategorized] ~122-~122: Did you mean “its” (the possessive pronoun)?
Context: ...ough that it's reproduced down below in it's entirety. ```wit package metatype:wit-...(ITS_PREMIUM)
[uncategorized] ~187-~187: Possible missing comma found.
Context: ...at-wire; } ``` Squint your eyes tight enough and thewit_wireprotocol as implemen...(AI_HYDRA_LEO_MISSING_COMMA)
[typographical] ~193-~193: It seems that a comma is missing.
Context: ...ing a bit more than acting as a boundary though. It was also responsible for setting up...(THOUGH_COMMA)
[misspelling] ~195-~195: This word is normally spelled as one.
Context: ...the user's Python snippets which are in free standinglambdaform. How does one create com...(EN_COMPOUNDS_FREE_STANDING)
[style] ~196-~196: The word ‘anyways’ is informal American English. Did you mean “anyway”?
Context: ...oes one create components out of Python anyways? [componentize-py](https://github.co...(ANYWAYS)
[uncategorized] ~199-~199: Possible missing article found.
Context: ...nts that are authored in Python. It has code generation suite that emits guest bindi...(AI_HYDRA_LEO_MISSING_A)
[uncategorized] ~203-~203: Possible missing comma found.
Context: ...e the actual preopens for the resulting component baking thelibpythonobject code into...(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~206-~206: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...thewit_wireinterface on the Typegate but this implementation is general across b...(COMMA_COMPOUND_SENTENCE_2)
[style] ~213-~213: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ...r and all. Sure, you only pay this cost only the first time you load the Python runt...(ADVERB_REPETITION_PREMIUM)
[uncategorized] ~213-~213: Possible missing comma found.
Context: ...odule as Wasmtime has great support for caching including on-disk caching. But 10 secon...(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~214-~214: Possible missing article found.
Context: ...ching. But 10 second is unacceptable in system that primarily serves HTTP requests as ...(AI_HYDRA_LEO_MISSING_A)
[uncategorized] ~214-~214: Possible missing comma found.
Context: ...le in system that primarily serves HTTP requests as these usually mean web apps running ...(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~217-~217: Possible missing comma found.
Context: ...er Wasmtime feature comes to the rescue here specifically their [AOT compilation](ht...(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~219-~219: Possible missing comma found.
Context: ... a sandbox. This eliminates the JIT cost but the nature of Wasm's bytecode semantics...(AI_HYDRA_LEO_MISSING_COMMA)
[misspelling] ~219-~219: This word is normally spelled as one.
Context: ...sm's bytecode semantics and the runtime safe-guards means that this is just as safe as inte...(EN_COMPOUNDS_SAFE_GUARDS)
[uncategorized] ~220-~220: Possible missing comma found.
Context: ... compressing it) in the Typegate binary itself ensuring minimal cold-starts for our py...(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~223-~223: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...Hopefully, all details were clear enough and please direct any feedback, questions, ...(COMMA_COMPOUND_SENTENCE_3)
|
@michael-0acf4 @zifeo @Natoandro I've mirrored the blog post on hackmd here. It should make it easier for edit work. Feel free to rework any sections or wording. |
Signed-off-by: Yohe-Am <56622350+Yohe-Am@users.noreply.github.com>
destifo
left a comment
There was a problem hiding this comment.
Lgtm! there's one image that doesn't load on the hackmd version of the blog, I'm guessing it's on the hackmd side only
Signed-off-by: Yohe-Am <56622350+Yohe-Am@users.noreply.github.com>
Running python with webassembly (part 1)
Migration notes
None
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Documentation