Skip to main content
modelstruct
=========
A simple Python module to expose SQLAlchemy model structures as a RESTful API.

## Example
Python model:

```python
class Book(db.Model):
__tablename__ = 'books'

id = db.Column(db.Integer, primary_key=True)
time_created = db.Column(db.DateTime)
name = db.Column(db.String(140), unique=True)
description = db.Column(db.String(320))
in_inventory = db.Column(db.Boolean, default=True)
user_id = db.Column(db.Integer)
author = db.Column(db.String(140))

def __init__(self, name, author, description, in_inventory, user_id):
self.name = name
self.description = description
self.in_inventory = in_inventory
self.user_id = user_id
self.time_created = datetime.datetime.now()
self.author = author

def __repr__(self):
return '<Book %r>' % self.id
```

JSON exposed via a RESTful API for this model:

```json
{
"structure": {
"author": "VARCHAR(140)",
"description": "VARCHAR(320)",
"id": "INTEGER",
"in_inventory": "BOOLEAN",
"name": "VARCHAR(140)",
"time_created": "DATETIME",
"user_id": "INTEGER"
}
}
```

## Install

```
pip install modelstruct
```

## Usage

1. Import the Python module
```python
from modelstruct import get_json
```

2. Create a new route for the endpoint you want to be your API (below the example is in Flask, and creates the API at the location `/models`, with the model class name `MODEL_NAME_HERE`)

```python
@app.route('/models', methods=['GET'])
def get_model_structure():
return get_json(MODEL_NAME_HERE)
```

3. That's it! Send a GET request to the endpoint and get the model's structure.

Release files for modelstruct 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modelstruct 1.0.0
File Size Uploaded
modelstruct-1.0.0.tar.gz 3.1 kB Details

Release files / modelstruct-1.0.0.tar.gz

Download URL modelstruct-1.0.0.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9e3a5d25bd90455c065ed008013727ea3712fe31b2b838e1f7777b567bcad5f1
BLAKE2b-256 checksum
How to use checksums
305c6a42e838b15b892dddf36b5a4498994743f935dab8495edb48f0a5fd1682
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page