An open API service indexing awesome lists of open source software.

https://github.com/rajatsandeepsen/interphase

Python Package for genarating typescript interface with git submodule folder structure
https://github.com/rajatsandeepsen/interphase

git-submodule interfaces pypi python typescript

Last synced: 16 days ago
JSON representation

Python Package for genarating typescript interface with git submodule folder structure

Awesome Lists containing this project

README

          

## Interphase - Bridging Backend and Frontend Development with Git Submodule

![alt text](./intro.png)

`Interphase` is a powerful `tool` + `git structure` designed to streamline the collaboration between backend and frontend developers by facilitating the sharing of critical information, including types, example data, API URLs, and documentation. The core concept is to provide an interconnected platform that enables seamless communication between these two development environments, thereby reducing friction and enhancing productivity, thus bridging the gap between the two development repository.

---

### Currently Available Support Packages
- [Interphase](https://pypi.org/project/Interphase/) - Python β†’ Typescript
- [Coming Soon]() - Go β†’ Typescript

### Requirements
> `Python >= 3.7`

### 1. Installation

```bash
$ pip install interphase
```

### 2. Quick Start

#### πŸ“ Simple folder structure
```
πŸ“ your_project
|
β”œβ”€β”€πŸ“ types (requied)
| |
β”‚ β””β”€β”€πŸ“„user.d.ts (optional)
|
β””β”€β”€πŸ“„main.py
```

#### πŸ“„main.py
```python
from interphase import typewriter

ts = typewriter("./types")

userData = {
"name": "John Doe",
"age": 30,
"email": "example@demo.com",
"skills": ["Python", "TypeScript", "JavaScript"]
}

ts.write('user', 'UserData', userData)
```

#### πŸ“„ user.d.ts
```typescript
export type UserData = {
name: string;
age: number;
email: string;
skills: string[];
}
```

### 3. Real Life Developer Usage

#### .gitmodules

```toml
[submodule "api"]
path = api
url = https://github.com/username/api.git
```

#### Frontend

```
πŸ“ FrontEnd-repo
β”‚
β”œβ”€β”€πŸ“ api (git submodule)
β”‚ β”‚
β”‚ β”œβ”€β”€πŸ“„__init__.py
β”‚ β”œβ”€β”€πŸ“„setup.py
β”‚ β”‚
β”‚ β””β”€β”€πŸ“ types
β”‚ β”‚
β”‚ β””β”€β”€πŸ“„ user.d.ts
β”‚
β”œβ”€β”€πŸ“ src
β”‚ β”‚
β”‚ β””β”€β”€πŸ“„ (other frontend files, where /api/types are imported and used)
β”‚
β”œβ”€β”€πŸ“„ package.json
β”œβ”€β”€πŸ“„ .gitmodules (important)
β””β”€β”€πŸ“„ .gitignore
```

#### Backend

```
πŸ“ Backend-repo
β”‚
β”œβ”€β”€πŸ“ api (git submodule)
β”‚ β”‚
β”‚ β”œβ”€β”€πŸ“„__init__.py
β”‚ β”œβ”€β”€πŸ“„setup.py
β”‚ β”‚
β”‚ β””β”€β”€πŸ“ types
β”‚ β”‚
β”‚ β””β”€β”€πŸ“„ user.d.ts
β”‚
β”œβ”€β”€πŸ“ src
β”‚ β”‚
β”‚ β””β”€β”€πŸ“„ (other backend files, where helps to create types for /api)
β”‚
β”œβ”€β”€πŸ“„ requirements.txt
β”œβ”€β”€πŸ“„ .gitmodules (important)
β””β”€β”€πŸ“„ .gitignore
```

### 4. Configuration

##### πŸ“„ /api/setup.py

```python
config = typewriter("./api/types", d_ts=True) # base setup
```
##### πŸ“„ /api/\_\_init\_\_.py

```python
from .setup import config as ts
```

### 5. API Reference

##### export types | interface
```python
ts = typewriter("./api/types")

# default is export enabled
ts.write('user', 'UserData', userData)
ts.write('user', 'UserData2', userData, export=False)

# default is type and interface can be enabled
ts.write('user', 'UserData3', userData, interface=True)
ts.write('user', 'UserData3', userData, export=False, interface=True)
```
```typescript
// user.d.ts

export type UserData = {...}
type UserData2 = {...}

export interface UserData3 {...}
interface UserData3 {...}
```

##### base folder
```python
# base directory can't be empty string
ts = typewriter("api/types")
ts = typewriter("./api/types")

# d.ts is defualt
# .ts can be enabled
ts = typewriter("./api/types", d_ts=False)
ts.write('user', 'UserData', userData)
```
```typescript
export type UserData = {...} // user.ts
```

##### file name
```python
# type name and file name can't be empty string
ts.write('user.ts', 'UserData', userData)
ts.write('user.d.ts', 'UserData', userData)

# d.ts is defualt
ts.write('user', 'UserData', userData)
```

### 6. Contributing Guide

We encourage contributions from the community to make Interphase even more powerful and versatile. If you find issues, have ideas for improvements, or want to suggest new features, please check our Contribution Guidelines for more information.

```bash
$ git clone https://github.com/rajatsandeepsen/interphase.git
$ cd interphase
```

```bash
$ pip install --upgrade setuptools
$ pip install --upgrade build
$ pip install --upgrade twine
```

```bash
$ python -m build # takes a lot of time
```
```
build result will be like:

πŸ“ interphase
β”œβ”€β”€πŸ“ interphase
β”œβ”€β”€πŸ“„pyproject.toml
β”œβ”€β”€πŸ“„requirements.txt
β”œβ”€β”€πŸ“„.gitignore
β”œβ”€β”€πŸ“„setup.py
β”‚
β””β”€β”€πŸ“ dist
β”‚
β”œβ”€β”€πŸ“„interphase-0.0.6.whl
β””β”€β”€πŸ“„interphase-0.0.6.tar.gz
```

```bash
# install from dist

$ pip install dist/interphase-0.0.6.whl
# or
$ pip install dist/interphase-0.0.6.tar.gz
```

```bash
# upload to pypi
$ python -m twine upload --repository pypi dist/*
# enter username & password from pypi
```

### 7. License

Interphase is not released under any License.

---

Feel free to customize and expand upon this draft to best reflect the features, benefits, and usage of your "Interphase" package.