Skip to main content

Dead simple way to define shared type definitions between applications

Project description

TypeBuf

PyPI version CircleCI codecov Maintainability Rating Reliability Rating


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

Install

pip install typebuf

Quickstart

  1. Create a file called types.yaml, it can be anywhere, like your project's root dir

  2. 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
  1. Now call TypeBuf with: $ typebuf compile -l python -l typescript

  2. You now have two new files, one called user.py and one called user.ts that 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

asciicast

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: string
    • fields: array[Field]
      • A Field has the following attributes:
        • name: string
        • type: string
        • optional: boolean

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

typebuf-0.1.2.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typebuf-0.1.2-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

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

Hashes for typebuf-0.1.2.tar.gz
Algorithm Hash digest
SHA256 792d32df55808e9e2db1d777d77b0462d3c1cc050a94bd7f9fa978f9a9dbf893
MD5 6ffc49eaf891e1c04fa270a8e0b28f99
BLAKE2b-256 2667b759b41c5321251c6a07f65dd69081fb349ba001cb32f7404cf50f4aa376

See more details on using hashes here.

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

Hashes for typebuf-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c1b09096e676b7de8312cc731a590e5aebada65fbc3c6320a0130568bcae5fcd
MD5 5b4311c5093a239b9e9319f7fbdfebb7
BLAKE2b-256 5593e888bc4d877749fa3e2d50cc545e1adc7b0cdd19d8f7b7adf3d9a022deed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page