datajoint-babel
Generate schema code from model definitions for both Python and MATLAB (and eventually vice versa).
Say you're a lab that uses both Python and MATLAB, this lets you declare your models once and then generate both Python and MATLAB versions of them, rather than having two potentially mutually contradictory sets of models. Keep explicit structure and avoid implicit model recreation from the database <3.
More generally a pythonic adapter interface from an explicit data model (thanks pydantic!) to datajoint models so other tools can patch in more easily!
So far just a single afternoon project, but will be the means by which autopilot interfaces directly with datajoint :)
Example
Source a model from a string
>>> from datajoint_babel.model import Table
>>> from pprint import pprint
>>> tab = Table.from_definition(name='User', tier='Manual', definition="""
# database users
username : varchar(20) # unique user name
---
first_name : varchar(30)
last_name : varchar(30)
role : enum('admin', 'contributor', 'viewer')
"""
)
>>> tab.dict()
{'name': 'User',
'tier': 'Manual',
'comment': {'comment': 'database users'},
'keys': [{'name': 'username',
'datatype': {'datatype': 'varchar', 'args': 20, 'unsigned': False},
'comment': 'unique user name',
'default': None}],
'attributes': [{'name': 'first_name',
'datatype': {'datatype': 'varchar', 'args': 30, 'unsigned': False},
'comment': '',
'default': None},
{'name': 'last_name',
'datatype': {'datatype': 'varchar', 'args': 30, 'unsigned': False},
'comment': '',
'default': None},
{'name': 'role',
'datatype': {'datatype': 'enum',
'args': ["'admin'", " 'contributor'", " 'viewer'"],
'unsigned': False},
'comment': '',
'default': None}]}
>>> pprint(tab.__dict__)
{'attributes': [Attribute(name='first_name', datatype=DJ_Type(datatype='varchar', args=30, unsigned=False), comment='', default=None),
Attribute(name='last_name', datatype=DJ_Type(datatype='varchar', args=30, unsigned=False), comment='', default=None),
Attribute(name='role', datatype=DJ_Type(datatype='enum', args=["'admin'", " 'contributor'", " 'viewer'"], unsigned=False), comment='', default=None)],
'comment': Comment(comment='database users'),
'keys': [Attribute(name='username', datatype=DJ_Type(datatype='varchar', args=20, unsigned=False), comment='unique user name', default=None)],
'name': 'User',
'tier': 'Manual'}
Export to python...
>>> print(tab.make(lang='python'))
@schema
class User(dj.Manual):
definition = """
# database users
username : varchar(20) # unique user name
---
first_name : varchar(30)
last_name : varchar(30)
role : enum('admin', 'contributor', 'viewer')
And to MATLAB
>>> print(tab.make(lang='matlab'))
%{
# # database users
# username : varchar(20) # unique user name
---
# first_name : varchar(30)
# last_name : varchar(30)
# role : enum('admin', 'contributor', 'viewer')
%}
classdef User < dj.Manual
end
Metadata
Release files for datajoint-babel 0.1.9
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 |
|---|---|---|---|---|
| datajoint-babel-0.1.9.tar.gz | 12.6 kB | Without provenance | Details for datajoint-babel-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datajoint_babel-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for datajoint_babel-0.1.9-py3-none-any.whl |
Total release size: 25.7 kB
Release files / datajoint-babel-0.1.9.tar.gz
| Download URL | datajoint-babel-0.1.9.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
472b9ea78d204f98d9b14e9b9f3d218289f8dd0d63ed52eff54d549633493def
|
|
BLAKE2b-256 checksum How to use checksums |
3ac36ad3363fe42a309491b6b486dd0fe205569de7b24f4d4767892df1794b6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.9.1 Darwin/21.4.0
|
Release files / datajoint_babel-0.1.9-py3-none-any.whl
| Download URL | datajoint_babel-0.1.9-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ab29a49d19acca43b5b57f8a85c489adbbf629e626f3fa4df653efac36b8e70
|
|
BLAKE2b-256 checksum How to use checksums |
3a4aea03e4717d119be47048bc0759bea1cac0d2166acfe0b2cd0b73cd24c5eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.9.1 Darwin/21.4.0
|
Security for datajoint-babel 0.1.9
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.