| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Fable is a compiler that translates F# source files to JavaScript and Python.
This Fable Python repository is a community driven project that contains the Python type bindings for Fable. The library will eventually contain Python (stdlib) bindings for Fable based on Python typeshed. It will also contain type binding for many other 3rd party libraries such as Flask, MicroBit and many more. Some bindings have already been added:
This library currently targets Python 3.9. Types bindings for other versions of Python should not be added to this library until we decide how to deal with Python version handling.
Prerequisite for compiling F# to Python using Fable:
> dotnet tool install --global fable --prerelease
> dotnet add package Fable.Core --prereleaseTo use the Fable.Python library in your Fable project:
> dotnet add package Fable.Pythonopen Fable.Python.Json
let object = {| A=10; B=20 |}
let result = json.dumps objectTo compile an F# Fable project to Python run e.g:
> fable --lang Python MyProject.fsprojFor more examples see the examples folder. It contains example code for using Fable Python with:
Fable.Python uses Poetry for package and dependency management. To handle dependencies when adding Fable Python compatible NuGet packages, you should use Femto.
This project is community driven. If the type binding you are looking for is currently missing, then you need to add them to the relavant files (or add new ones). Open a PR to get them included.
The src/stdlib directory contains type bindings for modules in the Python 3 standard library. We also accept type bindings for 3rd party libraries as long as:
There's not much Python specific documentation yet, but the process of adding type bindings for Python is similar to JS:
Note that import all is different from JS. E.g:
[<ImportAll("flask")>]
let flask: IExports = nativeOnlyThis will generate import flask and not a wildcard import from flask import *. The latter version is discoraged anyways.
Parts of this library could benefit from code-generation based on the type annotations in Python typeshed similar to ts2fable. Even so we should keep this library manually updated based on PRs to ensure the quality of the code.
Current plan:
Use a dedicated List.fs for Python. List.fs currently depends on Array.fs that is not an efficient list implmentation for Python.
Compile Fable.Library as a published library (done)
Use poetry for Python references to Fable modules (done)
Update docs
| Back | FazBrowse Home | New Git URL |