• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    F#
  • License
    MIT License
  • Created about 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python bindings for Fable

Fable Python

Build and Test Nuget

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:

  • Python Standard Libray
  • Jupyter
  • Flask
  • CogniteSdk

Version

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.

Installation

Prerequisite for compiling F# to Python using Fable:

> dotnet tool install --global fable --prerelease
> dotnet add package Fable.Core --prerelease

To use the Fable.Python library in your Fable project:

> dotnet add package Fable.Python

Usage

open Fable.Python.Json

let object = {| A=10; B=20 |}
let result = json.dumps object

To compile an F# Fable project to Python run e.g:

> fable --lang Python MyProject.fsproj

For more examples see the examples folder. It contains example code for using Fable Python with:

Libraries that uses or works with Fable Python

Poetry

Fable.Python uses Poetry for package and dependency management. To handle dependencies when adding Fable Python compatible NuGet packages, you should use Femto.

Contributing

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:

  • the package is publicly available on the Python Package Index;
  • the package supports any Python version supported by Fable Python; and
  • the package does not ship with its own stubs or type annotations

There's not much Python specific documentation yet, but the process of adding type bindings for Python is similar to JS:

Differences from JS

Note that import all is different from JS. E.g:

[<ImportAll("flask")>]
let flask: IExports = nativeOnly

This will generate import flask and not a wildcard import from flask import *. The latter version is discoraged anyways.

Auto-generation

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:

  1. Add bindings for Python ast module (in progress)
  2. Use ast module to parse Python typeshed annotations
  3. Generate F# bindings

Road-map

  • 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

More Repositories

1

Fable

F# to JavaScript, TypeScript, Python, Rust and Dart Compiler
F#
2,916
star
2

fable-react

Fable bindings and helpers for React and React Native
F#
273
star
3

ts2fable

Parser of Typescript declaration files
F#
223
star
4

fable-elmish-electron-material-ui-demo

Complete boilerplate for Electron apps using Fable and Elmish with hot module reloading, time-travel debugging, etc.
F#
112
star
5

Fable.Lit

Write Fable Elmish apps with Lit
F#
94
star
6

fable2-samples

Fable 2 samples
F#
68
star
7

fable-browser

Fable bindings for Browser Web APIs
F#
66
star
8

repl

Fable online REPL
F#
61
star
9

samples-electron

Fable bindings and samples for Github Electron
F#
60
star
10

fable-arch

Framework for building applications based on the elm architecture.
F#
60
star
11

Fable.Store

Manage state logic in Svelte, React apps and more
F#
59
star
12

fable-react-native

Fable bindings and helpers for React Native projects
F#
49
star
13

fable3-samples

Nagareyama (Fable 3) samples
F#
47
star
14

Fable.Solid

Fable bindings for SolidJS
F#
45
star
15

samples-browser

Fable samples for browser apps
F#
36
star
16

fable-powerpack

Utilities for Fable apps
F#
33
star
17

fable-import

Fable bindings for JavaScript libraries
F#
33
star
18

fable-electron

Fable bindings for Electron apps
F#
32
star
19

Feliz.JSX

Feliz API for JSX compilation
F#
30
star
20

Fable.Jupyter

F# (Fable) support for Jupyter
Jupyter Notebook
30
star
21

Fable.JsonProvider

F# JSON Type Provider for Fable
F#
28
star
22

fable-templates

Templates for Fable projects maintained by fable-compiler org
F#
26
star
23

static-web-generator

Simple Fable Node.js app to generate static pages
F#
24
star
24

fable-compiler.github.io

Fable web site
JavaScript
23
star
25

fable-graphics

Fable bindings for graphic tools: D3, DC, Three, Pixi
F#
23
star
26

fable-node

Bindings for node.js native modules
F#
21
star
27

cfworker-hello-world

Cloudflare worker
F#
19
star
28

fable-promise

Fable bindings for JS promise
F#
19
star
29

Fable.Flutter

Fable bindings for Flutter API
F#
18
star
30

fable-fetch

Fable bindings for Browsers' Fetch API
F#
17
star
31

samples-pixi

Pixi samples for Fable
CSS
15
star
32

repl-legacy

F#
14
star
33

Fable.RegexProvider

Simple Safe Regex Provider compatible with Fable
F#
12
star
34

Fable.Expect

Utilities to test Fable apps
JavaScript
11
star
35

webpack-config-template

Template for webpack.config.js in Fable projects
JavaScript
10
star
36

ts2fable-exports

All branches are auto-generated by ts2fable
F#
9
star
37

fable-recharts

Fable bindings for Recharts
F#
8
star
38

fable-vscode-extension

Example of a VS Code Extension Written in F#
F#
8
star
39

Fable.I18Next

Fable bindings and helpers for [i18next](https://www.i18next.com/)
JavaScript
7
star
40

community

Finder for community resources
F#
7
star
41

fable-pixi

Bindings For Pixi.js
F#
7
star
42

Fable.ReactGoogleMaps

Fable bindings and helpers for react-google-map
F#
7
star
43

fableconf-workshops

Workshops for FableConf
F#
5
star
44

fableconf

Material for fableconf
F#
4
star
45

rollup-plugin-fable

Rollup plugin for Fable (F# to JS compiler)
JavaScript
4
star
46

repl2

REPL for Fable 2
F#
3
star
47

repl3

F#
3
star
48

Fable.Package.SDK

F#
3
star
49

fable-import-ws

Fable bindings for Websockets library ws
F#
2
star
50

fable-date

F#
2
star
51

fable-import-google-cloud-functions

F#
2
star
52

Fable.React.UseElmish

useElmish React hook
F#
1
star
53

fable-react-dom

F#
1
star