Skip to main content

SQLAlchemy-Function defines a SQLALchemy Mixin for creating Function models.

A Function model has a parent (optional), a function, arguments, and keyword arguments. When called, the Function model executes its function, passing in its parent (if applicable), its arguments, and its keyword arguments.

Installation

$ pip install sqlalchemy-function

Quickstart

In the setup, we create a SQLAlchemy session, define a Parent model subclassing FunctionRelator, and a Function model subclassing FunctionMixin.

from sqlalchemy_function import FunctionMixin, FunctionRelator

from sqlalchemy import create_engine, Column, ForeignKey, Integer
from sqlalchemy.orm import relationship, sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base

# standard session creation
engine = create_engine('sqlite:///:memory:')
session_factory = sessionmaker(bind=engine)
Session = scoped_session(session_factory)
session = Session()
Base = declarative_base()

# define a Function model parent
class Parent(FunctionRelator, Base):
    __tablename__ = 'parent'
    id = Column(Integer, primary_key=True)

    # Fuction models must reference their parent with a `parent` attribute
    functions = relationship('Function', backref='parent')

# define a Function model with the FunctionMixin
class Function(FunctionMixin, Base):
    __tablename__ = 'function'
    id = Column(Integer, primary_key=True)
    parent_id = Column(Integer, ForeignKey('parent.id'))

Base.metadata.create_all(engine)

We can now register, store, and call functions as follows.

@Function.register
def foo(parent, *args, **kwargs):
    print('My parent is', parent)
    print('My args are', args)
    print('My kwargs are', kwargs)
    return 'return value'

parent = Parent()
Function.foo(parent, 'hello world', goodbye='moon')
parent.functions[0]()

Out:

My parent is <__main__.Parent object at 0x7f8b4d200518>
My args are ('hello world',)
My kwargs are {'goodbye': 'moon'}
'return value'

Citation

@software{bowen2020sqlalchemy-function,
  author = {Dillon Bowen},
  title = {SQLAlchemy-Function},
  url = {https://dsbowen.github.io/sqlalchemy-function/},
  date = {2020-06-05},
}

License

Users must cite this package in any publications which use it.

It is licensed with the MIT License.

Metadata

Release files for sqlalchemy-function 0.0.9

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

Source distribution (sdist)

Source distribution for sqlalchemy-function 0.0.9
File Size Uploaded Provenance Actions
sqlalchemy-function-0.0.9.tar.gz 4.7 kB Without provenance Details for sqlalchemy-function-0.0.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-function 0.0.9
File Interpreter ABI Platform Actions
sqlalchemy_function-0.0.9-py3-none-any.whl Python 3 none any Details for sqlalchemy_function-0.0.9-py3-none-any.whl

Total release size: 11.9 kB

Release files / sqlalchemy-function-0.0.9.tar.gz

Download URL sqlalchemy-function-0.0.9.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
50637b8a471b8841c574bf1c56816b727e70246805c7307bcd372dd1e1833518
BLAKE2b-256 checksum
How to use checksums
486b481f748fcd62b437bc71a8e4cd93460b019074685ae4d0450b7e015f751a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.8

Release files / sqlalchemy_function-0.0.9-py3-none-any.whl

Download URL sqlalchemy_function-0.0.9-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
205ae671d16146de6d53b99c0325cfe05fa4bee7ae00153d0a711ecef099b64f
BLAKE2b-256 checksum
How to use checksums
8701bae7db608bab520acdb0d6ec86ad978f3aece1bca28d00986a15767b134d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.8

Security for sqlalchemy-function 0.0.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.

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