Skip to content

Commit

Permalink
setup nav
Browse files Browse the repository at this point in the history
  • Loading branch information
tonybaloney committed Aug 3, 2024
1 parent fde4559 commit 099a010
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 40 deletions.
2 changes: 2 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 13 additions & 39 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

[![NuGet Version](https://img.shields.io/nuget/v/CSnakes)](https://www.nuget.org/packages/CSnakes)

<img src="res/logo.jpeg" alt="drawing" width="200"/>
![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.

<br /> <br />

## Features

Expand All @@ -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<T>` |
| `dict[K, V]` | `IReadOnlyDictionary<K, V>` |
| `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.
37 changes: 37 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
@@ -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<T>` |
| `dict[K, V]` | `IReadOnlyDictionary<K, V>` |
| `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.
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -17,4 +18,5 @@ markdown_extensions:
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
- pymdownx.superfences
- attr_list

0 comments on commit 099a010

Please sign in to comment.