{ "info": { "author": "Danish Abdullah", "author_email": "dev@danishabdullah.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Algen\n\nAlgen generates opionated ORM classes for sqlalchemy given a simple schema\neither as a commandline string or as a yaml file. It is designed to have\nminimal dependencies and is trivially extensible. A command line tool\nis bundled along to help generate the models. For DB specific types,\nonly postgres is currently supported. The tool currently assumes that\nsqlalchemy's declarative base object is to be imported like\n ```from .alchemy_base import Base```\nThe library prefers making the code verbose rather than concise for the\nsake of having better auto-completion and help from your editor/IDE\ne.g. first style is preferred to the second one:\n```python\ndef update(self, a=None, b=None):\n if a is not None:\n self.a = a\n if b is not None:\n self.b = b\n```\n```python\ndef update(self, **kwargs):\n for k,v in kwargs.items():\n if hasattr(self, k) and v is not None:\n setattr(self, k, v)\n```\n\n\n### CLI\n```bash\n$\u00a0algen --help\nUsage: algen [OPTIONS]\n\nOptions:\n -n, --name TEXT Name of model\n -c, --columns TEXT Column definition. e.g. col_name:col_type Can be\n used multiple times hence named columns. e.g. -c\n foo:Int -c bar:Unicode(20)\n -d, --destination PATH Destination directory. Default will assume 'models'\n directory inside the current working directory\n -y, --yaml PATH Yaml file describing the Model. This supersedes the\n column definition provided through --columns option.\n --help Show this message and exit.\n```\n\nGiven a file as follows:\n```yaml\nPerson:\n columns:\n - name: id\n type: BigInteger\n primary_key: True\n auto_increment: True\n - name: name\n type: Unicode(255)\n - name: is_vip\n type: Boolean\n - name: created_at\n type: DateTime(timezone=True)\n server_default: now() at time zone 'utc'\n - name: updated_at\n type: DateTime(timezone=True)\n server_default: now() at time zone 'utc'\n relationships:\n - name: addresses\n class: Address\n back_populates: 'person'\n\nAddress:\n columns:\n - name: id\n type: BigInteger\n primary_key: True\n auto_increment: True\n - name: line1\n type: Unicode()\n - name: line2\n type: Unicode()\n - name: line3\n type: Unicode()\n - name: postcode\n type: Unicode(10)\n index: True\n - name: created_at\n type: DateTime(timezone=True)\n server_default: now() at time zone 'utc'\n - name: updated_at\n type: DateTime(timezone=True)\n server_default: now() at time zone 'utc'\n foreign_keys:\n - name: person_id\n type: BigInteger\n reference:\n table: persons\n column: id\n nullable: False\n relationships:\n - name: person\n class: Person\n back_populates: 'addresses'\n\n```\n\nThe cli tool will create two the following two files ```person.py``` and ```address.py```.\n\n```python\nfrom __future__ import unicode_literals, absolute_import, print_function\n\nfrom collections import namedtuple\n\nfrom sqlalchemy import Column, Unicode, BigInteger, DateTime, ForeignKey\nfrom sqlalchemy.orm import relationship\n\n\nfrom .alchemy_base import Base\n\n__author__ = 'danishabdullah'\n\n\nclass Address(Base):\n __tablename__ = 'addresses'\n\n id = Column(BigInteger, auto_increment=True, primary_key=True)\n line1 = Column(Unicode(), )\n line2 = Column(Unicode(), )\n line3 = Column(Unicode(), )\n postcode = Column(Unicode(10), index=True)\n created_at = Column(DateTime(timezone=True), server_default=\"now() at time zone 'utc'\")\n updated_at = Column(DateTime(timezone=True), server_default=\"now() at time zone 'utc'\")\n\n # --- Foreign Keys ---\n person_id = Column(BigInteger, ForeignKey('persons.id'), nullable=False)\n\n # --- Relationships ---\n person = relationship('Person', back_populates='addresses')\n\n def __init__(self, id=None, line1=None, line2=None, line3=None, postcode=None, created_at=None, updated_at=None, person_id=None):\n self.id = id\n self.line1 = line1\n self.line2 = line2\n self.line3 = line3\n self.postcode = postcode\n self.created_at = created_at\n self.updated_at = updated_at\n self.person_id = person_id\n\n def add(self, session):\n session.add(self)\n\n def update(self, line1=None, line2=None, line3=None, postcode=None, created_at=None, updated_at=None, person_id=None):\n # This function only updates a value if it is not None.\n # Falsy values go through in the normal way.\n # To set things to None use the usual syntax:\n # Address.column_name = None\n\n if line1 is not None:\n self.line1 = line1\n\n if line2 is not None:\n self.line2 = line2\n\n if line3 is not None:\n self.line3 = line3\n\n if postcode is not None:\n self.postcode = postcode\n\n if created_at is not None:\n self.created_at = created_at\n\n if updated_at is not None:\n self.updated_at = updated_at\n\n if person_id is not None:\n self.person_id = person_id\n\n def delete(self, session):\n session.delete(self)\n\n def to_dict(self):\n return {x: y for x, y in self.__dict__.items() if not x.startswith(\"_sa\")}\n\n def get_proxy_cls(self):\n # AddressProxy is useful when you want to persist data\n # independent of the sqlalchemy session. It's just a namedtuple\n # that has very low memory/cpu footprint compared the regular\n # orm class instances.\n keys = self.to_dict().keys()\n name = \"AddressProxy\"\n return namedtuple(name, keys)\n\n def to_proxy(self):\n # Proxy-ing is useful when you want to persist data\n # independent of the sqlalchemy session. It's just a namedtuple\n # that has very low memory/cpu footprint compared the regular\n # orm class instances.\n cls = self._get_proxy_cls()\n return cls(**self.to_dict())\n\n @classmethod\n def from_proxy(cls, proxy):\n return cls(**proxy._asdict())\n\n def __hash__(self):\n return hash(str(self.id))\n\n def __eq__(self, other):\n return (self.id == other.id)\n\n def __neq__(self, other):\n return not (self.id == other.id)\n\n def __str__(self):\n return \"\".format(id=self.id)\n\n def __unicode__(self):\n return \"\".format(id=self.id)\n\n def __repr__(self):\n return \"\".format(id=self.id)\n\n```\n\n```python\nfrom __future__ import unicode_literals, absolute_import, print_function\n\nfrom collections import namedtuple\n\nfrom sqlalchemy import Column, Unicode, BigInteger, Boolean, DateTime\nfrom sqlalchemy.orm import relationship\n\n\nfrom .alchemy_base import Base\n\n__author__ = 'danishabdullah'\n\n\nclass Person(Base):\n __tablename__ = 'persons'\n\n id = Column(BigInteger, auto_increment=True, primary_key=True)\n name = Column(Unicode(255), )\n is_vip = Column(Boolean, )\n created_at = Column(DateTime(timezone=True), server_default=\"now() at time zone 'utc'\")\n updated_at = Column(DateTime(timezone=True), server_default=\"now() at time zone 'utc'\")\n\n # --- Foreign Keys ---\n\n\n # --- Relationships ---\n addresses = relationship('Address', back_populates='person')\n\n def __init__(self, id=None, name=None, is_vip=None, created_at=None, updated_at=None):\n self.id = id\n self.name = name\n self.is_vip = is_vip\n self.created_at = created_at\n self.updated_at = updated_at\n\n def add(self, session):\n session.add(self)\n\n def update(self, name=None, is_vip=None, created_at=None, updated_at=None):\n # This function only updates a value if it is not None.\n # Falsy values go through in the normal way.\n # To set things to None use the usual syntax:\n # Person.column_name = None\n\n if name is not None:\n self.name = name\n\n if is_vip is not None:\n self.is_vip = is_vip\n\n if created_at is not None:\n self.created_at = created_at\n\n if updated_at is not None:\n self.updated_at = updated_at\n\n def delete(self, session):\n session.delete(self)\n\n def to_dict(self):\n return {x: y for x, y in self.__dict__.items() if not x.startswith(\"_sa\")}\n\n def get_proxy_cls(self):\n # PersonProxy is useful when you want to persist data\n # independent of the sqlalchemy session. It's just a namedtuple\n # that has very low memory/cpu footprint compared the regular\n # orm class instances.\n keys = self.to_dict().keys()\n name = \"PersonProxy\"\n return namedtuple(name, keys)\n\n def to_proxy(self):\n # Proxy-ing is useful when you want to persist data\n # independent of the sqlalchemy session. It's just a namedtuple\n # that has very low memory/cpu footprint compared the regular\n # orm class instances.\n cls = self._get_proxy_cls()\n return cls(**self.to_dict())\n\n @classmethod\n def from_proxy(cls, proxy):\n return cls(**proxy._asdict())\n\n def __hash__(self):\n return hash(str(self.id))\n\n def __eq__(self, other):\n return (self.id == other.id)\n\n def __neq__(self, other):\n return not (self.id == other.id)\n\n def __str__(self):\n return \"\".format(id=self.id)\n\n def __unicode__(self):\n return \"\".format(id=self.id)\n\n def __repr__(self):\n return \"\".format(id=self.id)\n\n```\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/danishabdullah/algen", "keywords": "algen sqlalchemy orm model generation compiler postgres schema", "license": "The MIT License (MIT)\n\nCopyright (c) 2016 Danish Abdullah\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n", "maintainer": "", "maintainer_email": "", "name": "algen", "package_url": "https://pypi.org/project/algen/", "platform": "", "project_url": "https://pypi.org/project/algen/", "project_urls": { "Homepage": "https://github.com/danishabdullah/algen" }, "release_url": "https://pypi.org/project/algen/1.0.3/", "requires_dist": null, "requires_python": "", "summary": "algen", "version": "1.0.3" }, "last_serial": 4996109, "releases": { "0.9": [ { "comment_text": "built for Darwin-15.5.0", "digests": { "md5": "7a5ab3748c8ef420c87df955ef8d5ae1", "sha256": "09b714a21306735bbc8a08685e60d793da1b15b5830b8187178b6a3a67d3e4ed" }, "downloads": -1, "filename": "algen-0.9.macosx-10.5-x86_64.tar.gz", "has_sig": false, "md5_digest": "7a5ab3748c8ef420c87df955ef8d5ae1", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 17263, "upload_time": "2016-05-18T10:54:44", "url": "https://files.pythonhosted.org/packages/06/d8/b89d06a99d847602fa295fb10458e9a4aec0c90b101d7e5658ff5cbabc84/algen-0.9.macosx-10.5-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "3073a40715371658018097e203aee53b", "sha256": "39c693ced7064be557cf4b49334ab8e58de3ddf882d8d3b5b97d6c50e54e1a90" }, "downloads": -1, "filename": "algen-0.9.tar.gz", "has_sig": false, "md5_digest": "3073a40715371658018097e203aee53b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8875, "upload_time": "2016-05-18T10:54:32", "url": "https://files.pythonhosted.org/packages/af/54/1e880464ceb6fef076ab74d0d6e8d3a8e41cc222d37f38f35aa1c8df8713/algen-0.9.tar.gz" } ], "0.9.1": [ { "comment_text": "built for Darwin-15.5.0", "digests": { "md5": "9b5d26077eda4d55f2cc883f58f437be", "sha256": "e25de079dce1668dfb116104e281191827afec1c8cb6dd865509a14772be5965" }, "downloads": -1, "filename": "algen-0.9.1.macosx-10.5-x86_64.tar.gz", "has_sig": false, "md5_digest": "9b5d26077eda4d55f2cc883f58f437be", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 17669, "upload_time": "2016-05-19T09:42:38", "url": "https://files.pythonhosted.org/packages/d1/d7/839f1cee1e957bf03aa82518d164be9ac6b91f9cf20a3fbdb090a00691c4/algen-0.9.1.macosx-10.5-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "fbc3720ff68c1a5160dd727938b100f1", "sha256": "affc9b79896a0156688b8ad5e3ba19e1b9c06bdd1f207d440434f48085a54cd7" }, "downloads": -1, "filename": "algen-0.9.1.tar.gz", "has_sig": false, "md5_digest": "fbc3720ff68c1a5160dd727938b100f1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9714, "upload_time": "2016-05-19T09:42:15", "url": "https://files.pythonhosted.org/packages/a0/eb/ad859bc6eed735e605e8edb3674ad343e030edb1c601d322236ce735070f/algen-0.9.1.tar.gz" } ], "0.9.2": [ { "comment_text": "built for Darwin-15.5.0", "digests": { "md5": "5170fa4dca90162a86179d7c7ca69599", "sha256": "8a61b818ee2ffd385999f5d279683d1e52b24665c535fbc38fce020bdbc50973" }, "downloads": -1, "filename": "algen-0.9.2.macosx-10.5-x86_64.tar.gz", "has_sig": false, "md5_digest": "5170fa4dca90162a86179d7c7ca69599", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 17668, "upload_time": "2016-05-19T09:46:00", "url": "https://files.pythonhosted.org/packages/d8/f9/b4ef5c167dc0eb8f026542748b2457152b06a02f3d80a1fdf061edb6e199/algen-0.9.2.macosx-10.5-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "9dbcd5f9c53a5fa542bb1ccab373fdc4", "sha256": "71b3fc78362fe4d856f95d1d98cdb42813fb5b9ca2a1adf9f829c9c9f4cbfb40" }, "downloads": -1, "filename": "algen-0.9.2.tar.gz", "has_sig": false, "md5_digest": "9dbcd5f9c53a5fa542bb1ccab373fdc4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9722, "upload_time": "2016-05-19T09:45:46", "url": "https://files.pythonhosted.org/packages/b2/59/cd4d6de07e7f80cbe22ce82b585470ea187546fe0a4129294469f488d81e/algen-0.9.2.tar.gz" } ], "0.9.3": [ { "comment_text": "built for Darwin-15.5.0", "digests": { "md5": "0591afc8c512eea7211f8579f8dff49d", "sha256": "1296ddcd541190068ae7ebcd4888a8529134da23b1cefe0e3493894dbebd2dec" }, "downloads": -1, "filename": "algen-0.9.3.macosx-10.5-x86_64.tar.gz", "has_sig": false, "md5_digest": "0591afc8c512eea7211f8579f8dff49d", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 17697, "upload_time": "2016-05-19T10:41:18", "url": "https://files.pythonhosted.org/packages/d6/8e/26302ea9fe533a4e7211124b86289ca3a2d7fa8836499802c89e9f6c3bb2/algen-0.9.3.macosx-10.5-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "926560d8ec7b3670bd74c6ad72263c64", "sha256": "9758f0283aa8d157eccbab93b868df85dcc56e38ee4dea8fdb84632f23a6b2dd" }, "downloads": -1, "filename": "algen-0.9.3.tar.gz", "has_sig": false, "md5_digest": "926560d8ec7b3670bd74c6ad72263c64", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9744, "upload_time": "2016-05-19T10:41:02", "url": "https://files.pythonhosted.org/packages/0e/93/8caa9955ab20e2c7aa38e9c7a43993b3c98538549a8f2a5e0b45d075b1b8/algen-0.9.3.tar.gz" } ], "1.0": [ { "comment_text": "built for Darwin-15.5.0", "digests": { "md5": "0723672ed28a664d83a8e2f739f7d884", "sha256": "dbaecbc1a0facf085c3a13855748b38442b458022ea13d499969a705868860b3" }, "downloads": -1, "filename": "algen-1.0.macosx-10.5-x86_64.tar.gz", "has_sig": false, "md5_digest": "0723672ed28a664d83a8e2f739f7d884", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 20483, "upload_time": "2016-06-01T18:28:38", "url": "https://files.pythonhosted.org/packages/fc/ce/836fdd75e5be5429aa33de1f076829ba1373461a98118317ab2430b9dd4d/algen-1.0.macosx-10.5-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "323bbbd6f9bd1e4cf31d4ecaa289db3d", "sha256": "a57dddf31b76b3579a0b2e5e35fcd6c397131f09b75f1cca677b5d0071aea657" }, "downloads": -1, "filename": "algen-1.0.tar.gz", "has_sig": false, "md5_digest": "323bbbd6f9bd1e4cf31d4ecaa289db3d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11273, "upload_time": "2016-06-01T18:28:33", "url": "https://files.pythonhosted.org/packages/c1/c0/98b1d907c21ea1eca493a9b2e6765a2eb81f2c65e40096f441f29c50ffca/algen-1.0.tar.gz" } ], "1.0.1": [ { "comment_text": "built for Darwin-15.5.0", "digests": { "md5": "75499c2651400752f08ef14539a5aed5", "sha256": "76cbc4885027e093c06e23f8344633c50c5247915ae023ca8ffecf0bcccf2fe3" }, "downloads": -1, "filename": "algen-1.0.1.macosx-10.5-x86_64.tar.gz", "has_sig": false, "md5_digest": "75499c2651400752f08ef14539a5aed5", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 22260, "upload_time": "2016-06-02T07:33:15", "url": "https://files.pythonhosted.org/packages/18/a8/111e73b0d19c413379bb0f25d553eb90bb8926e7e6d13f24b982bfe66acc/algen-1.0.1.macosx-10.5-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "e8cd75c46a08c20d98d02e92d29c7fa6", "sha256": "2c2b04a2d690e138c8892e74c5aef75f41491b373f487cdc81865d21595eacfa" }, "downloads": -1, "filename": "algen-1.0.1.tar.gz", "has_sig": false, "md5_digest": "e8cd75c46a08c20d98d02e92d29c7fa6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11930, "upload_time": "2016-06-02T07:33:10", "url": "https://files.pythonhosted.org/packages/75/d3/d97a5f28222671bb93e3ef1933db4c8a36c831908554b2bf43a1991552ab/algen-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "built for Darwin-15.5.0", "digests": { "md5": "6bb4b7daa79d5a5ae7650bebda6bffde", "sha256": "22053786e03d8a1e2a2708aaca5f753b0c9a19e72a75403be0144833dd1e167f" }, "downloads": -1, "filename": "algen-1.0.2.macosx-10.5-x86_64.tar.gz", "has_sig": false, "md5_digest": "6bb4b7daa79d5a5ae7650bebda6bffde", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 22292, "upload_time": "2016-06-02T07:42:50", "url": "https://files.pythonhosted.org/packages/88/79/7b518e0002199634e9ec87440ceefff56f76571d243510125ef5fd75833e/algen-1.0.2.macosx-10.5-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "6f06981464e319e43f568b4858e684f6", "sha256": "6788604efb857fbbf45da62161fa858f6a243c549490ef5093741cc61c85119f" }, "downloads": -1, "filename": "algen-1.0.2.tar.gz", "has_sig": false, "md5_digest": "6f06981464e319e43f568b4858e684f6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11940, "upload_time": "2016-06-02T07:42:46", "url": "https://files.pythonhosted.org/packages/54/cc/14372457d966b0a0bdf69e9e7cd16ac3ef2acbec50d2e03ec6af1dae0dc4/algen-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "a15278329fbe2110aea38eb803414b99", "sha256": "2ab4b0169e45cc637a81c4dc6be0d6d4dbd495461effa3cb8a9a217a4290bfb3" }, "downloads": -1, "filename": "algen-1.0.3.tar.gz", "has_sig": false, "md5_digest": "a15278329fbe2110aea38eb803414b99", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14053, "upload_time": "2019-03-28T05:33:20", "url": "https://files.pythonhosted.org/packages/a2/90/d9a0dac1e2c094ce29090077124926f08cce15df7370355f705942e4ce18/algen-1.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a15278329fbe2110aea38eb803414b99", "sha256": "2ab4b0169e45cc637a81c4dc6be0d6d4dbd495461effa3cb8a9a217a4290bfb3" }, "downloads": -1, "filename": "algen-1.0.3.tar.gz", "has_sig": false, "md5_digest": "a15278329fbe2110aea38eb803414b99", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14053, "upload_time": "2019-03-28T05:33:20", "url": "https://files.pythonhosted.org/packages/a2/90/d9a0dac1e2c094ce29090077124926f08cce15df7370355f705942e4ce18/algen-1.0.3.tar.gz" } ] }