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
poetry add --dev typebuf
Quickstart
-
Create a file called
types.yaml, it can be anywhere in your project repo -
Add the following lines to the newly created file:
---
typedefs:
- typename: User
imports:
python:
- 'from typing import Optional'
fields:
- name: first_name
type: string
- 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 Optional
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 0.1.1. 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
-
Inside types.yaml there is an array called
typedefs. This is where you add your shared type definitions -
Each type can have the following fields (required fields in bold):
- typename: string
- imports: map[string, array[str]]
- fields: array[Field]
- A
Fieldhas the following attributes:- name: string
- type: string
- optional: boolean
- A
-
In a type definition you can also specify custom/required imports for any depedencies your classes may need:
-
typedefs: - typename: Address imports: python: - 'from mymodule.user import User' - 'from typing import Optional' typescript: - 'import { User } from "./User";' fields: - ...,
-
Metadata
Release files for typebuf 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| typebuf-0.1.4.tar.gz | 11.9 kB | Without provenance | Details for typebuf-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| typebuf-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for typebuf-0.1.4-py3-none-any.whl |
Total release size: 25.3 kB
Release files / typebuf-0.1.4.tar.gz
| Download URL | typebuf-0.1.4.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28262ccbae6708294f45ec965d6547e901e02e7fab595165ade7c1d63b0a5277
|
|
BLAKE2b-256 checksum How to use checksums |
475952d4beb85e718a451c79ceea1b442425926c031f052a0c884ac2cf034cf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.9.2 Linux/4.4.0-19041-Microsoft
|
Release files / typebuf-0.1.4-py3-none-any.whl
| Download URL | typebuf-0.1.4-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
28fbcd26e2eb7e481d6cbd62be26687902b93a437f682bed73e60c977f59dd44
|
|
BLAKE2b-256 checksum How to use checksums |
acf100a739ee6d4ed3210f0e3c5b60afab563629cc5f16f51c4971188df36567
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.9.2 Linux/4.4.0-19041-Microsoft
|
Security for typebuf 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.