{"id":18828545,"url":"https://github.com/isomeric/formal","last_synced_at":"2025-04-14T03:09:09.659Z","repository":{"id":57431927,"uuid":"164751046","full_name":"isomeric/formal","owner":"isomeric","description":"A Python library for object document mapping with MongoDB and SQL dialects using JSON schema.","archived":false,"fork":false,"pushed_at":"2021-02-22T16:42:14.000Z","size":1191,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T03:09:04.119Z","etag":null,"topics":["database","mongodb","objects","odm","orm","sql"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isomeric.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.rst","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-08T23:37:12.000Z","updated_at":"2021-02-22T16:42:17.000Z","dependencies_parsed_at":"2022-09-02T11:01:37.556Z","dependency_job_id":null,"html_url":"https://github.com/isomeric/formal","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isomeric%2Fformal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isomeric%2Fformal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isomeric%2Fformal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isomeric%2Fformal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isomeric","download_url":"https://codeload.github.com/isomeric/formal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813795,"owners_count":21165634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","mongodb","objects","odm","orm","sql"],"created_at":"2024-11-08T01:30:54.055Z","updated_at":"2025-04-14T03:09:09.633Z","avatar_url":"https://github.com/isomeric.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"|Build Status|\n\nFormal!\n=======\n\nA Python library for object document mapping with MongoDB and SQL\ndialects(WiP) using JSON schema.\n\nDescription\n-----------\n\nThis is a package for generating classes from a JSON-schema that are to be\nsaved in MongoDB or SQL and (un)pickled via Python's builtin json module or\nothers like simplejson or ujson.\n\nThis extends the JSON schema by supporting extra BSON types:\n\n-  ObjectId - use the ``\"object_id\"`` type in your JSON schema to\n   validate that\n   a field is a valid ObjectId.\n-  datetime - use the ``\"date\"`` type in your JSON schema to validate\n   that a field\n   is a valid datetime\n\nUsage\n-----\n\n1) Build your schema\n\n::\n\n        \u003e\u003e\u003e schema = {\n            'name': 'Country',\n            'id': '#country',\n            'properties': {\n                'name': {'type': 'string'},\n                'abbreviation': {'type': 'string'},\n            },\n            'additionalProperties': False,\n        }\n\n2) Connect to your database\n\n::\n\n        \u003e\u003e\u003e import formal\n        \u003e\u003e\u003e formal.connect(\"test\")\n\n3) Create a model\n\n::\n\n        \u003e\u003e\u003e Country = formal.model_factory(schema)\n\n4) Create an object using your model\n\n::\n\n        \u003e\u003e\u003e sweden = Country({\"name\": 'Sweden', \"abbreviation\": 'SE'})\n        \u003e\u003e\u003e sweden.save()\n        \u003e\u003e\u003e sweden._id\n        ObjectId('50b506916ee7d81d42ca2190')\n\n5) Let the object validate itself!\n\n::\n\n        \u003e\u003e\u003e sweden = Country.find_one({\"name\" : \"Sweden\"})\n        \u003e\u003e\u003e sweden.name = 5\n        Traceback (most recent call last):\n          File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n          File \"formal/model.py\", line 254, in __setattr__\n            self.validate_field(attr, self._schema[\"properties\"][attr], value)\n          File \"formal/model.py\", line 189, in validate_field\n            self.validate_simple(key, value_schema, value)\n          File \"formal/model.py\", line 236, in validate_simple\n            (key, value_type, str(value), type(value)))\n        formal.exceptions.ValidationError: Field 'name' is of type 'string', received '5' (\u003ctype 'int'\u003e)\n\n        \u003e\u003e\u003e sweden.overlord = 'Bears'\n        Traceback (most recent call last):\n          File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n          File \"formal/model.py\", line 257, in __setattr__\n            raise ValidationError(\"Additional property '%s' not allowed!\" % attr)\n        formal.exceptions.ValidationError: Additional property 'overlord' not allowed!\n\n6) You can also update objects from dictionaries:\n\n::\n\n        \u003e\u003e\u003e sweden.update({\"name\": \"Sverige\"})\n        \u003e\u003e\u003e sweden.save()\n\n7) To get them to a browser or other similar things, serialize them:\n\n::\n\n        \u003e\u003e\u003e sweden.serializablefields()\n        {'_id': '50b506916ee7d81d42ca2190', 'name': 'Sverige', 'abbreviation': 'SE', 'id': '#country'}\n\nChoosing a collection\n---------------------\n\n| By default Formal will use the pluralized version of the model's name.\n  If\n| you want to use something else, put it in the JSON-schema:\n\n::\n\n        {\n            \"name\": \"MyModel\",\n            ...\n            \"collectionName\": \"some_collection\",\n            ...\n        }\n\nMultiple Databases\n------------------\n\nTo use multiple databases, simply call ``connect()`` multiple times:\n\n::\n\n        \u003e\u003e\u003e import formal\n        \u003e\u003e\u003e formal.connect(\"test\")\n        \u003e\u003e\u003e formal.connect(\"other_db\")\n\n| By default all models will use the first database specified. If you\n  want to use\n| a different one, put it in the JSON-schema:\n\n::\n\n        {\n            \"name\": \"MyModel\",\n            ...\n            \"databaseName\": \"other_db\",\n            ...\n        }\n\nSQL Operation\n-------------\n\n..is still work in progress.\n\nRoadmap\n=======\n\nWe have many plans for the future:\n\n-  Complete SQL support including:\n\n   -  JSON document storage\n   -  GeoJSON queries\n\n-  Time series support\n-  Support for consensus algorithms like Paxos or Raft\n-  Automatic data migration (up and down)\n-  Improved testing\n\n   -  multiple interpreters via tox\n   -  complete coverage\n   -  more tests\n\nPing us, if you'd like to contribute!\n\nHistory\n=======\n\nFormal is a fork of warmongo, originally written by Rob Britton.\n\nThings that have changed:\n\n-  jsonschema is now truly used to validate objects (it validates far\n   more than just basetypes)\n-  we do ignore mongo's object\\_id - not sure if this is a good thing,\n   but it helps with the schemata\n-  we require (by spec) an 'id' field that lists a uri for the schema\n-  the resulting field is enforced on instantiated objects, too, so\n   clients can validate by schema-id\n\nWork in progress:\n\n-  Migration of versioned object models\n-  SQL integration\n-  Deep dot notation\n-  Delta operation for concurrent editing and object history\n\nLicence\n=======\n\nApache Version 2.0\n\nChange notice\n-------------\n\n| This file has been changed by the Hackerfleet Community and a change\n  notice has\n| been added to all modified files in accordance to the Apache License\n  2.0\n\nProduction Examples\n===================\n\n| The Isomer framework uses Formal as object document mapping system to\n  deal with data objects in a developer and\n| enduser friendly way.\n| See it in action on http://github.com/isomeric/isomer\n\n| The original author uses Warmongo every day at his startup\n  http://www.sweetiq.com/ to share data\n| definitions between their Python and Node.js applications. It has been\n  running in\n| production for some time now, so it has been reasonably tested for\n  robustness and performance.\n\n.. |Build Status| image:: https://travis-ci.org/isomeric/formal.svg\n   :target: https://travis-ci.org/isomeric/formal\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisomeric%2Fformal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisomeric%2Fformal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisomeric%2Fformal/lists"}