Dead simple way to define shared type definitions between applications
Project description
TypeBuf
Dead simple way to create shared type definitions between applications
- Other tools have too much setup? Too much boilerplate? Do too much "magic"? Just:
- Define your Types in
types.yaml - Run TypeBuf:
$ typebuf compile -f types.yaml -l python -l typescript
- Define your Types in
Install
pip install typebuf
Quickstart
-
Create a file called
types.yaml, it can be anywhere, like your project's root dir -
Add the following lines to the newly created file:
---
typedefs:
- typename: User
fields:
- name: first_name
type: string
optional: false
- name: age
type: int
optional: true
-
Now call TypeBuf with:
$ typebuf compile -l python -l typescript -
You now have two new files, one called
user.pyand one calleduser.tsthat can you use for things like data serialization/deserialization, validation, subclassing, etc
Generated Python:
"""
User type definition file generated by TypeBuf
Note: Any changes made to this file will be overwritten
during next compilation
"""
from typing import *
class User:
first_name: str
age: Optional[int]
Generated TypeScript:
/**
* User type definition file generated by TypeBuf
* Note: Any changes made to this file will be overwritten
* during next compilation
*/
interface User {
first_name: string;
age?: number;
}
Note: So far only Python and TypeScript are supported. More languages coming soon!
Demo
Here's a quick demo of me using TypeBuf. First I show the contents of the types.yaml file then I generate Python and TypeScript source code and show the contents of the new files
Documentation
- Reads only a file named
types.yaml(for now) - Inside that file there is an array called
typedefs. This is where you add your shared type definitions - Each type will have the following fields:
typename: stringfields: array[Field]- A
Fieldhas the following attributes:- name: string
- type: string
- optional: boolean
- A
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file typebuf-0.1.2.tar.gz.
File metadata
- Download URL: typebuf-0.1.2.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.15.6-2-MANJARO
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
792d32df55808e9e2db1d777d77b0462d3c1cc050a94bd7f9fa978f9a9dbf893
|
|
| MD5 |
6ffc49eaf891e1c04fa270a8e0b28f99
|
|
| BLAKE2b-256 |
2667b759b41c5321251c6a07f65dd69081fb349ba001cb32f7404cf50f4aa376
|
File details
Details for the file typebuf-0.1.2-py3-none-any.whl.
File metadata
- Download URL: typebuf-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.15.6-2-MANJARO
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1b09096e676b7de8312cc731a590e5aebada65fbc3c6320a0130568bcae5fcd
|
|
| MD5 |
5b4311c5093a239b9e9319f7fbdfebb7
|
|
| BLAKE2b-256 |
5593e888bc4d877749fa3e2d50cc545e1adc7b0cdd19d8f7b7adf3d9a022deed
|