{ "info": { "author": "John-Paul Jorissen", "author_email": "jjorissen52@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: Microsoft :: Windows :: Windows 10", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "## python-firestore-models\n\nThis library serves as a wrapper around Google's Firestore. It implements validation, type checking facilities, \nand relational (work in progress) model logic.\n\n## When to Use\n\nWhen you want a simple abstraction layer on top of Firestore to help you keep track of entities and their relationships,\nthe way you would achieve it with an ORM. The library's API borrows several design paradigms from Django's ORM, because \nI like Django's ORM.\n\n## Installation\n`pip install `\n\n\n## Basic Usage\n\n### Environment\nYou will need to set up your environment in the usual way to have access to your resources on\nGoogle Cloud Platform.\n\n```\nimport os\nos.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/path/to/credentials.json'\n```\n\nIf you do not have this variable set, model instances will log a warning, and nothing will\nactually work with Firestore.\n\n### Creating, Fetching, and Deleting\n```\nfrom fsmodels.models import Model\nfrom fsmodels.fields import Field\n\ndef is_valid_string(value):\n return value is None or isinstance(value, str), f'value must be str, cannot be {value}'\n\n\nclass User(Model):\n\n username = Field(required=True)\n password = Field(required=True)\n first_name = Field(required=True, default='Billy')\n last_name = Field(validation=is_valid_string)\n created_date = Field(default=time.time)\n \n \nmy_user = User(username='user1', password='goodpassword')\nmy_user.save() # automatically generates a new id and creates this user in firestore.\nmy_user.retrieve() # returns a dict of the record in firestore\nmy_user.delete() # deletes the record in firestore with my_user.id\n\n\nmy_user2 = User(username='user2') # validation functions are not called on __init__ by defalt\nmy_user2.save() # raises a validation error; password is a required field.\n```\n\n### Edit Existing\n```\nuser = User(id='my_id') \n\n# retrieve ignores everything about the local model instance other than the id \nuser.retrieve(overwrite_local=True)\n\nprint(user.to_dict()) # see what was in firestore\nuser.first_name = 'a different name'\nuser.save()\n```\n\n### Delete Existing\n```\nuser = User(id='my_id') \n \nuser.delete()\n```\n\n## Advanced Usage\n### One to One Relationships\n\n```\nimport uuid\n\nfrom fsmodels.models import Model\nfrom fsmodels.fields import Field, ModelField, IDField\n\ndef uuid_as_str():\n return str(uuid.uuid4())\n\nclass Profile(Model):\n id = IDField(required=True, default=uuid_as_str)\n first_name = Field(required=True)\n last_name = Field(required=True)\n\nclass User(Model):\n id = IDField(required=True, default=uuid_as_str)\n username = Field(required=True)\n password = Field(required=True)\n profile = ModelField(Profile, required=True)\n \nprofile = Profile(first_name='Billy', last_name='Mayes')\n# will save both the profile and the user\nuser = User(username='bmayes', password='plaintextpassword', profile=profile)\n\nprint(user.retrieve())\n#{'profile': {'id': 'bd3ca41a-b6c4-4249-ac48-eb05db79bb3d',\n# 'first_name': 'Billy',\n# 'last_name': 'Mayes'},\n# 'password': 'plaintextpassword',\n# 'username': 'bmayes',\n# 'profile_id': 'bd3ca41a-b6c4-4249-ac48-eb05db79bb3d',\n# 'id': '1e586d79-f2c0-4618-a7f7-95308a54298e'}\n\nprint(profile.retrieve())\n#{'user_id': '1e586d79-f2c0-4618-a7f7-95308a54298e',\n# 'first_name': 'Billy',\n# 'last_name': 'Mayes',\n ```\n \n ### One to Many Relationships\n Planned.\n \n ### Overriding Defaults\n```\n# model_name in error messages and collection name in firestore is my_model1\nclass MyModel1(Model):\n first_name = Field(required=True)\n last_name = Field(required=True)\n \n class Meta:\n model_name = 'Profiles'\n \n# model_name in error messages and collection name in firestore is MY-MODEL-2\nclass MyModel2(Model):\n first_name = Field(required=True)\n last_name = Field(required=True)\n \n class Meta:\n model_name = 'MY-MODEL-2'\n \n# model_name in error messages is my_model3 and collection name in firestore is mY-mODeL-3\nclass MyModel3(Model):\n first_name = Field(required=True)\n last_name = Field(required=True)\n \n class Meta:\n collection = 'mY-mODeL-3'\n```\n \n### Using Google's firestore API\n```\nclass MyModel1(Model):\n first_name = Field(required=True)\n last_name = Field(required=True)\n\nm = MyModel1()\n\n# same as google.cloud.firestore\nm.firestore\n# same as google.cloud.firestore.Client()\nm.db\n# same as google.cloud.firestore.Client().collection(m._collection) where m._collection in this case is my_model1\nm.collection\n\n# you can do stuff like\nfor record in m.collection.get():\n print(record.to_dict())\n```", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/CorrDyn/python-firestore-models", "keywords": "Python Firestore Models ORM Wrapper", "license": "Apache", "maintainer": "", "maintainer_email": "", "name": "fsmodels", "package_url": "https://pypi.org/project/fsmodels/", "platform": "", "project_url": "https://pypi.org/project/fsmodels/", "project_urls": { "Homepage": "https://github.com/CorrDyn/python-firestore-models" }, "release_url": "https://pypi.org/project/fsmodels/0.1.0.dev0/", "requires_dist": null, "requires_python": "", "summary": "This library serves as a wrapper around Google's Firestore. It implements validation, type checking facilities, and relational (work in progress) model logic.", "version": "0.1.0.dev0" }, "last_serial": 5239192, "releases": { "0.1.0.dev0": [ { "comment_text": "", "digests": { "md5": "ece338350943591b00fc6bc65a95f4d3", "sha256": "480a04155e65444cb5b73b53516ec2727a1f54c51fc07707d9cdf8a391b2abd8" }, "downloads": -1, "filename": "fsmodels-0.1.0.dev0.tar.gz", "has_sig": false, "md5_digest": "ece338350943591b00fc6bc65a95f4d3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13356, "upload_time": "2019-05-07T17:36:16", "url": "https://files.pythonhosted.org/packages/05/8b/abfcb08f57217df6085101f3bbe16f784d6a08c1c41d917c125790411ff8/fsmodels-0.1.0.dev0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ece338350943591b00fc6bc65a95f4d3", "sha256": "480a04155e65444cb5b73b53516ec2727a1f54c51fc07707d9cdf8a391b2abd8" }, "downloads": -1, "filename": "fsmodels-0.1.0.dev0.tar.gz", "has_sig": false, "md5_digest": "ece338350943591b00fc6bc65a95f4d3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13356, "upload_time": "2019-05-07T17:36:16", "url": "https://files.pythonhosted.org/packages/05/8b/abfcb08f57217df6085101f3bbe16f784d6a08c1c41d917c125790411ff8/fsmodels-0.1.0.dev0.tar.gz" } ] }