Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Translates an OpenAPI schema to SQLAlchemy models.
Supports OpenAPI 3.0 and 3.1.
Get started with the online editor that will guide you through using your
existing OpenAPI specification to define your database schema and offers
installing your models using pip
:
Online Editor
python -m pip install OpenAlchemy
# To be able to load YAML file
python -m pip install OpenAlchemy[yaml]
For example, given the following OpenAPI specification:
# ./examples/simple/example-spec.yml
openapi: "3.0.0"
info:
title: Test Schema
description: API to illustrate OpenAlchemy MVP.
version: "0.1"
paths:
/employee:
get:
summary: Used to retrieve all employees.
responses:
200:
description: Return all employees from the database.
content:
application/json:
schema:
type: array
items:
"$ref": "#/components/schemas/Employee"
components:
schemas:
Employee:
description: Person that works for a company.
type: object
x-tablename: employee
properties:
id:
type: integer
description: Unique identifier for the employee.
example: 0
x-primary-key: true
x-autoincrement: true
name:
type: string
description: The name of the employee.
example: David Andersson
x-index: true
division:
type: string
description: The part of the company the employee works in.
example: Engineering
x-index: true
salary:
type: number
description: The amount of money the employee is paid.
example: 1000000.00
required:
- id
- name
- division
The SQLALchemy models file then becomes:
# models.py
from open_alchemy import init_yaml
init_yaml("./examples/simple/example-spec.yml")
The Base and Employee objects can be accessed:
from open_alchemy.models import Base
from open_alchemy.models import Employee
With the models_filename parameter a file is auto generated with type hints for the SQLAlchemy models at the specified location, for example: type hinted models example. This adds support for IDE auto complete, for example for the model initialization:
and for properties and methods available on an instance:
An extensive set of examples with a range of features is here:
An example API has been defined using connexion and Flask here:
integer
(32 and 64 bit),number
(float only),boolean
,string
,password
,byte
,binary
,date
,date-time
,$ref
references for columns and models,$ref
to other files on the same file system
(not supported on Windows),$ref
to other files at a URL,allOf
inheritance for columns and models,from_str
model methods to construct from JSON string,from_dict
model methods to construct from dictionaries,to_str
model methods to convert instances to JSON string,__str__
model methods to support the python str
function,__repr__
model methods to support the python repr
function,to_dict
model methods to convert instances to dictionaries,readOnly
and writeOnly
for influence the conversion to and from
dictionaries,open_alchemy.models
removing the need for
models.py
files,x-
prefix or a namespaced x-open-alchemy-
prefix for
extension properties andFork and checkout the repository. To install:
poetry install
To run tests:
poetry run pytest
Make your changes and raise a pull request.
poetry shell
cd docs
make html
This creates the index.html
file in docs/build/html/index.html
.
rm -r dist/*
poetry build
poetry publish
FAQs
Maps an OpenAPI schema to SQLAlchemy models.
We found that openalchemy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.