This project is a Python implementation of the Embedded Sass Host, providing a Python API for the Dart Sass compiler using the embedded protocol. It follows the established patterns from the reference implementation but is adapted for Python's ecosystem.
The project is complete and ready for publication with comprehensive functionality, extensive testing, and production-ready quality.
- 12 value types implemented with full API compatibility
- Singleton patterns for
SassBoolean,SassNull - Immutable data structures using
immutableslibrary - Color space conversions (RGB ↔ HSL ↔ HWB)
- Comprehensive type assertions and validation
- Bidirectional Python ↔ Protobuf conversion
- 125+ test cases with 100% pass rate
- Protocol buffer integration with generated Python bindings
- Custom varint encoder/decoder for message framing
- MessageTransformer with streaming support and buffering
- RequestTracker for thread-safe request management
- Message dispatcher with callback routing
- Complete error handling with source locations
- Cross-platform compiler detection with multiple fallback strategies
- AsyncCompiler with subprocess management
- SyncCompiler following established patterns
- CLI tool for command-line compatibility
- Lazy initialization and graceful cleanup
- Process lifecycle management (fixed hanging process issues)
- Internal function registry for protocol message handling
- Internal importer registry for protocol message handling
- Custom function callbacks with full value conversion
- Custom importer callbacks with canonicalize and load support
- Protocol-level message routing and response handling
- Complete API compatibility with embedded protocol specification
- Bidirectional conversion between Python Sass values and protobuf messages
- All Sass value types supported: boolean, null, string, number, list, map, color, functions
- Type safety with comprehensive validation
- 18 comprehensive test cases with 100% pass rate
- Complete compilation pipeline working
- Synchronous and asynchronous APIs both functional
- Custom functions and importers fully integrated
- Error handling with proper source location reporting
- Process cleanup preventing resource leaks
- Total Tests: 278 passing
- Pass Rate: 100%
- Coverage Areas:
- Value type behavior and validation
- Protocol communication and streaming
- Compiler lifecycle management
- Function and importer callbacks
- Cross-platform compatibility
- Error handling and edge cases
- Integration testing with real Sass compilation
# Singleton pattern with identity-based equality
sass_true = SassBoolean(True)
sass_false = SassBoolean(False)
assert sass_true is SassBoolean.sass_true
# Immutable collections with structural sharing
sass_list = SassList([sass_true, SassString("hello")])
sass_map = SassMap({SassString("key"): SassNumber(42)})# Cross-platform executable discovery
compiler_command = get_compiler_command()
# Returns: ['dart', '/path/to/sass.snapshot'] or ['sass'] or ['/custom/path']
# Synchronous compilation (Node.js compatible)
result = compile_string('$color: blue; .test { color: $color; }')
print(result.css)
# Asynchronous compilation
result = await compile_async('style.scss')
print(result.css)# Custom functions are passed via options (Node.js compatible)
def pow_function(args):
base = args[0].assert_number().value
exponent = args[1].assert_number().value
return SassNumber(base ** exponent)
# Use in compilation
result = compile_string('.test { width: pow(2px, 3); }', {
'functions': {
'pow($base, $exponent)': pow_function
}
})
# Output: .test { width: 8px; }# Message encoding with varint length prefix
message = proto.InboundMessage()
encoded = message_transformer.encode(message)
# Streaming decode with buffering
transformer.decode_stream(partial_data)
# Emits complete messages via reactive streams# Clone and install dependencies
git clone <repo>
cd embedded-host-python
uv sync
# Run tests
uv run pytest
# Format code
uv run black .
uv run isort .import dart_sass as sass
# Compile file
result = sass.compile('style.scss')
print(result.css)
# Compile string
result = sass.compile_string('$color: blue; .test { color: $color; }')
print(result.css)
# Async compilation
result = await sass.compile_async('style.scss')
print(result.css)
# Custom functions via options (Node.js compatible)
def double(args):
return SassNumber(args[0].assert_number().value * 2)
result = sass.compile_string('.test { width: double(21px); }', {
'functions': {'double($number)': double}
})
# Output: .test { width: 42px; }- Package name:
python-dart-sass - Import name:
dart_sass - Version:
0.1.0 - Python requirement:
>=3.10 - Dependencies: All specified and tested
- Build system: Hatchling with proper configuration
- Comprehensive README with examples and API documentation
- Installation instructions and usage examples
- API reference for all public interfaces
- Contributing guidelines and development setup
- Changelog with detailed release notes
- Performance claims removed (no unsubstantiated claims)
- Proper attribution to Harvey McQueen with Amazon Q CLI acknowledgment
- Type hints throughout codebase
- Comprehensive tests with 100% pass rate
- Code formatting with black/isort/ruff
- Cross-platform compatibility (Linux, macOS, Windows)
- Memory management with proper cleanup
- Error handling with detailed messages
- Proven architecture with battle-tested patterns
- Protocol compatibility ensures consistent behavior
- Community familiarity for developers coming from Node.js
- Maintenance alignment with official implementation updates
- Performance benefits - subprocess reuse and efficient I/O
- Simpler mental model for most use cases
- Better error handling with direct subprocess communication
- Sync wrapper available for traditional blocking operations
- Sass values are immutable by specification
- Thread safety for concurrent operations
- Performance benefits with structural sharing
- Prevents accidental mutations in user code
- Python 3.10+ (tested on 3.12)
- Cross-platform (Linux, macOS, Windows)
- Architecture: x86_64, ARM64
- Dart Sass 1.45.0+ via embedded protocol
- Full Sass specification support
- Custom functions and importers
- All Sass value types supported
- Source maps and advanced features
The project follows modern Python development practices:
- Type hints throughout codebase
- Comprehensive tests for all functionality
- Code formatting with black/isort/ruff
- Async/await patterns for I/O operations
- Documentation with examples and API reference
Key areas for future contribution:
- Performance optimizations and benchmarking
- Additional platform support and testing
- Advanced error reporting enhancements
- Documentation improvements and examples
- ✅ Complete Embedded Sass Protocol implementation
- ✅ Synchronous and asynchronous APIs
- ✅ Custom function and importer support
- ✅ Complete Sass value system
- ✅ Cross-platform compiler integration
- ✅ Comprehensive test suite (278 passing tests)
- ✅ Full documentation and examples
- ✅ Production-ready code quality
The project is complete and ready for:
- GitHub repository creation and code publication
- PyPI package publication for easy installation
- Documentation hosting and community engagement
- Framework integrations (Django, Flask, FastAPI)
- Performance benchmarking and optimization
Status: 🎉 READY TO SHIP!