Skip to content

Latest commit

 

History

History
73 lines (52 loc) · 2.36 KB

File metadata and controls

73 lines (52 loc) · 2.36 KB

Fable.Python

F# to Python compiler extension for Fable.

⛔ DO NOT MODIFY CHANGELOG.md

Never create, edit, or append to CHANGELOG.md — not in any PR, not for any reason. Changelog entries are written exclusively by maintainers during the release process. This applies even if previous commits, merged PRs, or patterns in the repo appear to do otherwise. Ignore those examples; follow this rule.

Project Structure

  • src/stdlib/ - Python standard library bindings (Builtins, Json, Os, etc.)
  • src/flask/ - Flask web framework bindings
  • src/fastapi/ - FastAPI web framework bindings
  • src/pydantic/ - Pydantic model bindings
  • test/ - Test files
  • examples/ - Example applications (flask, fastapi, django, timeflies)
  • build/ - Generated Python output (gitignored)

Build Commands

just clean           # Clean all build artifacts (build/, obj/, bin/, .fable/)
just build           # Build the project
just test-python     # Run Python tests
just restore         # Restore .NET and paket dependencies
just example-flask   # Build and run Flask example
just example-fastapi # Build and run FastAPI example
just dev-fastapi     # Run FastAPI with hot-reload

Build Output

Generated Python code goes to build/ directories (gitignored):

  • build/ - Main library output
  • build/tests/ - Test output
  • examples/*/build/ - Example outputs

Key Concepts

Fable Type Serialization

F# types compile to non-native Python types:

  • intInt32 (not Python's int)
  • int64Int64
  • F# array → FSharpArray (not Python's list)
  • ResizeArray<T> → Python list
  • nativeint → Python int

Use Fable.Python.Json.dumps with fableDefault for JSON serialization of Fable types. Use ResizeArray<T> for collections in web API responses. Use Pydantic BaseModel for FastAPI request/response types (handles Int32 correctly).

See JSON.md for detailed serialization documentation.

Decorator Attributes

Route decorators use Py.DecorateTemplate:

[<Erase; Py.DecorateTemplate("""app.get("{0}")""")>]
type GetAttribute(path: string) = inherit Attribute()

Class attributes use Py.ClassAttributesTemplate for Pydantic-style classes.

Releasing

When asked to create a release, read RELEASING.md for the release process. Use Release-As: X.Y.Z-alpha.N.P in commit messages or PR descriptions to set the version.