PacDessert1436.PythonNetTemplateVB
1.0.1
See the version list below for details.
dotnet new install PacDessert1436.PythonNetTemplateVB@1.0.1
Python.NET Templates for VB.NET, by Pac-Dessert1436
A comprehensive set of VB.NET templates for creating desktop applications with Python integration using Python.NET, including both general-purpose Python templates and specialized bioinformatics templates using Biopython.
This template package is designed to enable VB.NET developers to leverage the power of Python.NET, and create robust desktop applications with Python integration. It also enforces Option Strict On in all templates to streamline code structure, prevent runtime errors, ensure type safety and code readability, and reduce technical debt.
v1.0.1 Latest Update: This update includes the following enhancements:
- ๐งน Code Cleanup: Removed unused variables, namespace imports, and simplified Python runtime state checking by replacing the
IsPythonInitializedbacking field with direct use ofPythonEngine.IsInitialized- โจ Feature Completion: Fully implemented sequence record demo functionality in the Biopython WPF template, now supporting DNA, RNA, and protein sequences from user input with proper FASTA format output
โ ๏ธ Warning: NO DYNAMIC TYPING in VB.NET
This template package strictly enforces Option Strict On in all templates and does NOT support dynamic typing with Python.NET objects.
Dynamic typing (using Option Strict Off and the dynamic Object type) with Python.NET's PyObject is strongly discouraged in VB.NET due to:
- Type safety issues: Loss of compile-time type checking
- Performance overhead: Runtime type resolution penalties
- Debugging difficulties: Obscure error messages and runtime failures
- Maintenance challenges: Code becomes harder to understand and maintain
Recommended Approach
Always use Python.NET's strongly-typed API methods to handle PyObject objects, including:
GetAttrandSetAttrto access and modify attributes ofPyObjectobjects.InvokeandInvokeMethodto call methods onPyObjectobjects.GetItemandSetItemto access and modify items inPyObjectobjects.
Templates Included
1. Python Console Application (VB.NET)
A general-purpose console application template with Python.NET integration for seamless Python interop.
Short Name: pyappvb
Identity: PacDessert1436.PythonNetTemplateVB.Python.Console
Features:
- Python runtime initialization and management
- Direct Python expression evaluation
- Execute Python code blocks from VB.NET
- Proper GIL (Global Interpreter Lock) handling
- Example Python integration scenarios
- Cross-platform console application support
2. Python WPF Desktop Application (VB.NET)
A modern WPF desktop application template with Python.NET integration.
Short Name: pywpfvb
Identity: PacDessert1436.PythonNetTemplateVB.Python.WPF
Features:
- Python runtime integration in WPF applications
- Interactive UI with Python backend processing
- Thread-safe Python calls from WPF UI thread
- Example Python integration patterns
- Modern MVVM-ready WPF architecture
3. BioPython Console Application (VB.NET)
A console-based bioinformatics application template leveraging Python's Biopython library.
Short Name: biopyappvb
Identity: PacDessert1436.PythonNetTemplateVB.BioPython.Console
Features:
- DNA/RNA/Protein sequence analysis
- Reverse complement, transcription, translation
- GC/AU content calculation
- Sequence record formatting (FASTA)
- Biopython object wrappers for type-safe access
- Comprehensive bioinformatics workflows
4. BioPython WPF Desktop Application (VB.NET)
A feature-rich WPF desktop application for bioinformatics sequence analysis.
Short Name: biopywpfvb
Identity: PacDessert1436.PythonNetTemplateVB.BioPython.WPF
Features:
- Interactive sequence analysis interface
- Support for DNA, RNA, and protein sequences
- Real-time sequence validation
- Visual display of analysis results
- GC/AU content calculation
- Nucleotide/amino acid frequency analysis
- FASTA format support
- Professional WPF UI with modern styling
Prerequisites
- .NET SDK 10: Download from dotnet.microsoft.com
- Python 3.11 or later: Download from python.org
- Biopython Library: Install via pip:
pip install biopython - Python.NET: Install via NuGet (automatically included in templates)
Installation
Install Templates
dotnet new install PacDessert1436.PythonNetTemplateVB
Verify Installation
dotnet new --list
You should see all four templates listed:
| Template Name | Short Name |
|---|---|
| Python Console Application (VB.NET) | pyappvb |
| Python WPF Desktop Application (VB.NET) | pywpfvb |
| BioPython Console Application (VB.NET) | biopyappvb |
| BioPython WPF Desktop Application (VB.NET) | biopywpfvb |
Usage
Create a Python Console Application
dotnet new pyappvb -n MyPythonConsoleApp
cd MyPythonConsoleApp
dotnet run
Create a Python WPF Desktop Application
dotnet new pywpfvb -n MyPythonWPFApp
cd MyPythonWPFApp
dotnet run
Create a BioPython Console Application
dotnet new biopyappvb -n MyBioConsoleApp
cd MyBioConsoleApp
dotnet run
Create a BioPython WPF Desktop Application
dotnet new biopywpfvb -n MyBioWPFApp
cd MyBioWPFApp
dotnet run
Project Structure
Python Console Application Structure
MyPythonConsoleApp/
โโโ PythonBridge.vb ' Python runtime management utilities
โโโ Program.vb ' Main application entry point
โโโ PythonAppVB.vbproj ' Project file
Python WPF Application Structure
MyPythonWPFApp/
โโโ PythonBridge.vb ' Python runtime management utilities
โโโ MainWindow.xaml ' Main UI window
โโโ MainWindow.xaml.vb ' UI event handlers and logic
โโโ App.xaml ' Application definition
โโโ PythonWPFVB.vbproj ' Project file
BioPython Console Application Structure
MyBioConsoleApp/
โโโ BioPyWrappers/
โ โโโ BioPyObject.vb ' Base wrapper class for Python objects
โ โโโ Seq.vb ' Wrapper for Biopython Seq objects
โ โโโ MutableSeq.vb ' Wrapper for Biopython MutableSeq objects
โ โโโ SeqRecord.vb ' Wrapper for Biopython SeqRecord objects
โโโ PythonBridge.vb ' Python runtime management utilities
โโโ Program.vb ' Main application entry point
โโโ BioPythonAppVB.vbproj ' Project file
BioPython WPF Application Structure
MyBioWPFApp/
โโโ BioPyWrappers/
โ โโโ BioPyObject.vb ' Base wrapper class for Python objects
โ โโโ Seq.vb ' Wrapper for Biopython Seq objects
โ โโโ MutableSeq.vb ' Wrapper for Biopython MutableSeq objects
โ โโโ SeqRecord.vb ' Wrapper for Biopython SeqRecord objects
โโโ PythonBridge.vb ' Python runtime management utilities
โโโ MainWindow.xaml ' Main UI window
โโโ MainWindow.xaml.vb ' UI event handlers and logic
โโโ App.xaml ' Application definition
โโโ BioPythonWPFVB.vbproj ' Project file
Key Features
Python.NET Integration (All Templates)
All templates provide seamless Python integration using Python.NET:
- Automatic Python runtime initialization and cleanup
- Proper GIL (Global Interpreter Lock) management
- Direct evaluation of Python expressions from VB.NET
- Execute Python code blocks within VB.NET applications
- Thread-safe Python calls for multi-threaded environments
- Comprehensive error handling for Python operations
Bioinformatics Capabilities (BioPython Templates)
Specialized bioinformatics functionality using Biopython:
- DNA Analysis: Reverse complement, transcription, translation, GC content
- RNA Analysis: Reverse complement, translation, AU content
- Protein Analysis: Sequence validation, amino acid property analysis
- Sequence Records: FASTA format support and manipulation
- Type-Safe Wrappers: VB.NET wrapper classes for Biopython objects
- Comprehensive Workflows: Pre-built bioinformatics analysis pipelines
General-Purpose Python Templates
Flexible Python integration for any type of application:
- Console Applications: Cross-platform console apps with Python logic
- WPF Applications: Modern desktop apps with Python backend processing
- MVVM-Ready: WPF templates designed for MVVM architecture
- Example Patterns: Pre-built Python integration examples
- Extensible Architecture: Easy to add custom Python functionality
Best Practices
All templates follow .NET and Python best practices:
- Resource Management: Proper use of
Usingstatements for Python objects - Error Handling: Comprehensive try-catch blocks and user-friendly error messages
- Thread Safety: GIL handling for multi-threaded WPF applications
- Clean Architecture: Separation of concerns between Python interop and application logic
- Maintainable Code: Consistent coding style and documentation
Customization
Adding New Biopython Wrappers
- Create a new class in the
BioPyWrappersdirectory - Inherit from
BioPyObject(Of T) - Implement wrapper methods for Biopython functionality
Example:
Public Class MyBioWrapper
Inherits BioPyObject(Of Object)
Public Sub New(pyObj As IntPtr)
MyBase.New(pyObj)
End Sub
Public Sub MyMethod()
InvokeMethod("my_method")
End Sub
End Class
Extending Functionality
Use the provided helper methods in PythonBridge.vb:
EvalPyExpr(Of T): Evaluate Python expressions and return strongly-typed resultsExecPyCode: Execute Python code blocksStartPythonRuntime: Initialize Python environmentStopPythonRuntime: Clean up Python environment
Troubleshooting
Python Runtime Errors
- Ensure Python is installed and available in PATH
- Verify Biopython is installed:
pip install biopython - Check that the Python version matches the template's pythonVersion parameter
Interop Errors
- Make sure Python.NET is compatible with your Python version
- Check for architecture mismatches (x86 vs x64)
- Verify that all required Python libraries are installed
WPF UI Issues
- Ensure .NET Desktop Runtime is installed
- Check for missing NuGet packages
- Verify that the project builds correctly before running
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
Support
For support, please open an issue in the repository, or contact me via email: benjamin_2001@qq.com.
License
BSD 3-Clause License. See the LICENSE file for details.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.