Skir is a powerful declarative language that shares the same goals as Protobuf but does a few things better, for example: polymorphism (via Rust-like enums), GitHub imports, built-in compatibility checks, a first-in-class DX.
Skir is a modern declarative language designed for defining data types, constants, and APIs, providing a streamlined alternative to Protocol Buffers. By utilizing a .skir file for schema definitions, users can generate idiomatic, type-safe code across multiple programming languages such as TypeScript, Python, Java, Go, C++, and more.
Key Features
- One schema, nine languages, zero friction: Create a single YAML configuration, execute one command, and utilize a watch mode that automatically refreshes generated code upon changes.
- End-to-end type safety: Maintain alignment of client/server contracts through shared method and type definitions prior to runtime.
- SkirRPC + Studio: Access a lightweight HTTP RPC along with a built-in Studio application for method browsing and testing.
- GitHub imports: Import types directly from GitHub repositories, facilitating the seamless sharing of data structures across different projects.
- Serialization modes: Support various serialization formats including dense JSON for APIs/databases, human-readable JSON for debugging, and binary formats for optimal performance.
- Safe schema evolution: Ensure backward compatibility with built-in checks and clearly defined rules for deserialization.
- Rust-like enums: Employ variants that can be constants or carry typed payloads, promoting clean polymorphism.
- Immutable generated models: Achieve deep immutability (except in C++), necessitating required fields during construction.
- Key-indexed arrays: Easily declare arrays, enabling fast key-based lookup APIs with syntax like
[User|user_id]. - First-class tooling: Leverage a VS Code extension and Language Server Protocol (LSP) support for validation, autocompletion, and formatting.
- Easy to extend: Integrate custom generators into the workflow as they are regular NPM modules.
Syntax Example
Below is a simple example of a schema definition in Skir:
struct Point {
x: int32;
y: int32;
label: string;
}
struct Shape {
points: [Point];
/// A short string describing this shape.
label: string;
}
const TOP_RIGHT_CORNER: Point = {
x: 600,
y: 400,
label: "top-right corner",
};
/// Returns true if no part of the shape's boundary curves inward.
method IsConvex(Shape): bool = 12345;
The above definitions compile into native, type-safe code that can be utilized in various projects. For example, in Python:
# my_project.py
from skirout.shapes_skir import Point # Python module generated by Skir
point = Point(x=3, y=4, label="P")
# Round-trip serialization to JSON
point_json = Point.serializer.to_json(point)
restored = Point.serializer.from_json(point_json)
assert(restored == point)
Supported Languages
Skir supports various programming languages with comprehensive documentation and examples:
| Language | Documentation | Example |
|---|---|---|
| 🟦 TypeScript | Documentation | Example |
| 🐍 Python | Documentation | Example |
| ⚡ C++ | Documentation | Example |
| ☕ Java | Documentation | Example |
| 💜 Kotlin | Documentation | Example |
| 🦀 Rust | Documentation | Example |
| 🐹 Go | Documentation | Example |
| 🎯 Dart | Documentation | Example |
| 🐦 Swift | Documentation | Example |
For more detailed information about getting started, refer to the documentation.
Explore Skir for an efficient and type-safe approach to data definition and serialization.
No comments yet.
Sign in to be the first to comment.