=========
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.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| modelstruct-1.0.0.tar.gz | 3.1 kB | Without provenance | Details for modelstruct-1.0.0.tar.gz |
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 |
Security for modelstruct 1.0.0
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.