Skip to content

Commit bcb38f7

Browse files
author
Maxime Mangel
committed
Add getting-started for python
1 parent 7b89015 commit bcb38f7

File tree

4 files changed

+73
-8
lines changed

4 files changed

+73
-8
lines changed
Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,73 @@
11
---
2-
title: TypeScript
2+
title: Python
33
layout: standard
44
---
55

6+
7+
This section is specific to Python targetting, it will guide you through the process of setting up your project and using Fable with Python.
8+
9+
:::info
10+
Please make sure you followed the [Fable setup guide](/docs/2-steps/your-first-fable-project) before continuing.
11+
:::
12+
13+
14+
<ul class="textual-steps">
15+
16+
<li>
17+
18+
Run your code.
19+
20+
```bash
21+
python3 program.py
22+
```
23+
24+
</li>
25+
26+
<li>
27+
28+
When targeting Python, you will want to install the `Fable.Python` package. It provides a set of bindings to the Python standard library, and so others common libraries.
29+
30+
```bash
31+
dotnet add package Fable.Python
32+
```
33+
34+
</li>
35+
36+
37+
<li>
38+
39+
Change the content of `Program.fs` to the following:
40+
41+
```fs
42+
43+
open Fable.Python.Builtins
44+
45+
let file = builtins.``open``("test.txt", OpenTextMode.Write)
46+
file.write("Hello World!") |> ignore
47+
```
48+
649
:::info
7-
This section is under construction.
8-
:::
50+
Python bindings are early stage, so some APIs are not yet available.
51+
52+
You can report missing APIs or send PR on the [Fable.Python repository](https://github.com/fable-compiler/Fable.Python)
53+
:::
54+
55+
</li>
56+
57+
<li>
58+
59+
Run Fable in watch mode
60+
61+
```bash
62+
dotnet fable watch
63+
```
64+
65+
If you run your node script again, you should see a new file `test.txt` with the content `Hello World`.
66+
67+
Try changing the content of `Hello World` to something else and re-run your script.
68+
69+
You should see that Fable re-compile your code and the file content changed.
70+
71+
</li>
72+
73+
</ul>

docs/docs/getting-started/typescript.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,12 @@ Run Fable and TypeScript in watch mode.
120120

121121
The follwing command start Fable in watch mode, and after the first Fable compilation, it will start TypeScript in watch mode.
122122

123-
In the [TypeSript]() section, we will learn how to use [Fun.Build]()
124-
to organize and simplify our build process.
125-
126123
```bash
127124
dotnet fable watch --lang typescript --run npx tsc Program.fs.ts --target es2022 --watch --preserveWatchOutput
128125
```
129126

127+
> You can use your favorite build system instead to launch the different commands in parallel.
128+
130129
If you run your node script again, you should see a new file `test.txt` with the content `Hello World`.
131130

132131
Try changing the content of `Hello World` to something else and re-run your script.

docs/docs/getting-started/your-first-fable-project.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ To go further look into the respective target documentation to have an example o
8181

8282
- [JavaScript](/docs/getting-started/javascript.html)
8383
- [TypeScript](/docs/getting-started/typescript.html)
84-
<!-- - [Dart](/docs/getting-started/dart.html)
8584
- [Python](/docs/getting-started/python.html)
85+
<!-- - [Dart](/docs/getting-started/dart.html)
8686
- [Rust](/docs/getting-started/rust.html)
8787
- [PHP](/docs/getting-started/php.html) -->
8888

docs/docs/menu.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"docs/getting-started/setup",
1616
"docs/getting-started/your-first-fable-project",
1717
"docs/getting-started/javascript",
18-
"docs/getting-started/typescript"
18+
"docs/getting-started/typescript",
19+
"docs/getting-started/python"
1920
]
2021
},
2122
{

0 commit comments

Comments
 (0)