diff --git a/docs/getting-started.md b/docs/getting-started.md index d666b48e..da8ddd30 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -17,6 +17,8 @@ To get started with CSnakes, you need to: ## Using type annotations for reflection +See the [reference supported types](reference.md#supported-types) for a list of Python types and their C#.NET equivalents. + ## Installing the nuget packages for CSnakes ## Marking files for generation diff --git a/docs/index.md b/docs/index.md index ec4808bb..aa806fa7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2,11 +2,13 @@ [![NuGet Version](https://img.shields.io/nuget/v/CSnakes)](https://www.nuget.org/packages/CSnakes) -drawing +![logo](res/logo.jpeg){ align=left width=30% } -CSnakes is a .NET Source Generator and Runtime that you can use to embed Python code and libraries into your .NET Solution without the need for REST, HTTP, or Microservices. +CSnakes is a .NET Source Generator and Runtime that you can use to embed **Python** code and libraries into your **C#.NET Solution** at a performant, low-level without the need for REST, HTTP, or Microservices. -![image](https://github.com/tonybaloney/PythonCodeGen/assets/1532417/39ca2f2a-416b-447a-a237-59e9613a4990) +Check out the [getting started](getting-started.md) guide or check out the [demo solution](https://github.com/tonybaloney/CSnakes/tree/main/samples) to see more. + +

## Features @@ -19,43 +21,15 @@ CSnakes is a .NET Source Generator and Runtime that you can use to embed Python - Supports nested sequence and mapping types (`tuple`, `dict`, `list`) - Supports default values +## Benefits + +- Uses native Python type hinting standards to produce clean, readable C# code with minimal boiler plate! +- Integration between .NET and Python is done at the C-API, meaning strong compatibility between Python versions 3.8-3.12 and .NET 6-8. +- Integration is low-level and high-performance. +- CSnakes uses the CPython C-API and is compatible with all Python extensions. +- Invocation of Python code and libraries is in the same process as .NET + ## Example CSnakes will generate a C#.NET class for any Python file in a project that is tagged as CSharp Analyzer Additional File (see [Getting Started](getting-started.md)). All functions in that class with type annotations will be reflected to callable C# methods and an environment builder added to that module. - -## Supported Types - -CSnakes supports the following typed scenarios: - -| Python type annotation | Reflected C# Type | -|------------------------|-------------------| -| `int` | `long` | -| `float` | `double` | -| `str` | `string` | -| `bool` | `bool` | -| `list[T]` | `IEnumerable` | -| `dict[K, V]` | `IReadOnlyDictionary` | -| `tuple[T1, T2, ...]` | `(T1, T2, ...)` | - -### Return types - -The same type conversion applies for the return type of the Python function, with the additional feature that functions which explicitly return type `None` are declared as `void` in C#. - -### Default values - -CSnakes will use the default value for arguments of types `int`, `float`, `str`, and `bool` for the generated C# method. For example, the following Python code: - -```python -def example(a: int = 123, b: bool = True, c: str = "hello", d: float = 1.23) -> None - ... - -``` - -Will generate the following C#.NET method signature: - -```csharp -public void Example(long a = 123, bool b = true, string c = "hello", double d = 1.23) -``` - -1. CSnakes will treat `=None` default values as nullable arguments. The Python runtime will set the value of the parameter to the `None` value at execution. diff --git a/docs/reference.md b/docs/reference.md new file mode 100644 index 00000000..94389683 --- /dev/null +++ b/docs/reference.md @@ -0,0 +1,37 @@ +# Reference + +## Supported Types + +CSnakes supports the following typed scenarios: + +| Python type annotation | Reflected C# Type | +|------------------------|-------------------| +| `int` | `long` | +| `float` | `double` | +| `str` | `string` | +| `bool` | `bool` | +| `list[T]` | `IEnumerable` | +| `dict[K, V]` | `IReadOnlyDictionary` | +| `tuple[T1, T2, ...]` | `(T1, T2, ...)` | + +### Return types + +The same type conversion applies for the return type of the Python function, with the additional feature that functions which explicitly return type `None` are declared as `void` in C#. + +### Default values + +CSnakes will use the default value for arguments of types `int`, `float`, `str`, and `bool` for the generated C# method. For example, the following Python code: + +```python +def example(a: int = 123, b: bool = True, c: str = "hello", d: float = 1.23) -> None + ... + +``` + +Will generate the following C#.NET method signature: + +```csharp +public void Example(long a = 123, bool b = true, string c = "hello", double d = 1.23) +``` + +1. CSnakes will treat `=None` default values as nullable arguments. The Python runtime will set the value of the parameter to the `None` value at execution. diff --git a/mkdocs.yml b/mkdocs.yml index f84dd5c6..dcedf6a3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -2,6 +2,7 @@ site_name: CSnakes nav: - Home: index.md - Getting Started: getting-started.md + - Reference: reference.md - Limitations: limitations.md - Examples: examples.md @@ -17,4 +18,5 @@ markdown_extensions: pygments_lang_class: true - pymdownx.inlinehilite - pymdownx.snippets - - pymdownx.superfences \ No newline at end of file + - pymdownx.superfences + - attr_list \ No newline at end of file