Name | pgfm JSON |
Version |
0.7.3
JSON |
| download |
home_page | None |
Summary | Python client for FileMaker Web APIs. |
upload_time | 2024-07-25 13:27:28 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | None |
keywords |
filemaker
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
``pgfm``: a Python client for FileMaker Server Web APIs
============================================================
:version: ``pgfm`` 0.7.3, July 25, 2023.
:contact: Mikhail Edoshin
The |pgfm| module is a Python client for |FileMaker|_ Server Web APIs. It aims to support all FileMaker APIs in a unified and transparent manner.
.. warning:: This is a work in progress. The current version supports the XML
API, both old and new formats. It does not yet fully support container
fields, and layout information in ``FMPXMLLAYOUT`` format and the whole
Data API. Another thing in progress are user and developer documentation.
Sample usage
------------
A FileMaker server at ``http://fm.example.com`` hosts a file **Sample** with toy orders:
.. figure:: https://github.com/MikhailEdoshin/pgfm/raw/main/res/figure-1.png
:scale: 75
The schema of the **Sample** file and a layout to fetch data.
We need to write backend code that receives a customer ID, requests all orders of that customer from FileMaker along with their most recent event, and returns them back to the caller as a JSON object with the following structure::
{ type: "customerOrders" customerId
orders: [
{ orderId statusTime statusName
items: [
{ productId productName price quantity } ] } ] }
To support that a FileMaker developer added a layout **Web.Orders**. The layout does a good half of the work to shape the result: it defines the fields that will be returned and arranges things so that the fields from the **Event** table show the most recent event.
To use the layout the backend needs send a search request to this layout, get back the result, and process the data to rearrange them as required. With |Pgfm| the simplest way to achieve that would look so:
.. _snippet:
.. code:: Python
import pgfm
def customerOrders(customerId):
# -> customerId: customer ID, int.
# <- result, list, JSON-compatible.
res = dict(type="customerOrders", customerId=customerId, orders=[])
usr = pgfm.User("username", "********")
srv = pgfm.Srv("https://fm.example.com/", usr)
req = pgfm.ReqLaySel() \
.db("Sample") \
.lay("Web.Orders") \
.col("customerId", customerId) \
.sort("Event::time", "descend")
for rec in srv.send(req).read():
order = dict(
orderId = rec.col("id"),
statusTime = rec.col("Event::time").toPyDatetime().isoformat(),
statusName = rec.col("Event::type"),
items = [])
res.orders.append(order)
for row in rec.rel("OrderItem"):
order.items.append(dict(
productId = row.col("productId"),
productName = row.col("Product::name"),
price = row.col("Product::price"),
quantity = row.col("quantity")))
return res
The ``res`` is the resulting object. The ``usr`` is the account we use to send the request and ``srv`` is the FileMaker server. The ``req`` is a request: something like a form that describes the desired action. Here we are going to ask the server to search for records (``ReqLaySel``) and specify the necessary details: file, layout and search criteria.
We also specify we want to get the results sorted by the **Event::time** field. Although the layout is set up to show the last event, the sort command will sort the orders by their first event. In our case it is fine, but generally it is one of specific FileMaker things one has to intimately understand.
We send the request to the server and immediately read the response. The result is an iterable of records so we also immediately start iterating over them. If something goes wrong with an HTTP request or a FileMaker response the code will automatically raise an exception.
For each record we create a new ``dict`` (``order``) and fill it with data from the record’s fields. The module reads FileMaker field values as string-like objects that can be safely used in any string context. By default they will be formatted according to FileMaker rules: for example, a date would come out as ``M/D/Y``. They are not really strings though; they know their specific type and expose methods to correctly convert their values into other representations. In our case we want to format the timestamps according to ISO 8601, so we convert them first to a Python ``datetime`` and then format the result with ``isoformat()``.
We also add a list for order items. Then we get a portal to the **OrderItem** table, loop through its rows, for each row create another ``dict`` and immediately place it into the ``items`` list.
In the end we return the result. We used only ``list`` and ``dict`` instances and FileMaker values are strings, so the result can be safely serialized into JSON.
License
-------
The module is available under the MIT license. The data used for the examples in the documentation are dervied from a sample database from |Contoso|_.
Usage
-----
The module uses third-party libraries ``lxml`` and ``requests``. The source code is available on GitHub_. The author, Mikhail Edoshin, can be reached there or via email: one_, another_.
.. _GitHub: https://github.com/MikhailEdoshin/pgfm/
.. _one: mikhail.edoshin@proofgeist.com
.. _another: mikhail.edoshin@mail.ru
Development
-----------
The project contains the following files::
/
|_ LICENSE -- licence (MIT)
|_ Makefile -- Makefile; run 'make' to see help
|_ README.rst -- The 'README' file (this one)
|_ pyproject.toml -- Python package specification
|_ requirements.txt -- Python requirements.
|_ res\
| |_ figure-1.png -- resources for 'README'
|_ src\
| |_ pgfm.py -- the module
|_ tests\
|_ test.py -- tests
Use ``Makefile`` to set up the virtual environment for interactive use and tests. The Python package is built with ``flit``.
.. References
.. |Contoso| replace:: one of Microsoft projects (licensed under MIT)
.. _Contoso: https://github.com/microsoft/Windows-appsample-customers-orders-d
atabase
.. |FileMaker| replace:: FileMaker
.. _FileMaker: https://www.claris.com/filemaker/
.. |Pgfm| replace:: ``pgfm``
.. |Pip| replace:: ``pip``
Raw data
{
"_id": null,
"home_page": null,
"name": "pgfm",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "FileMaker",
"author": null,
"author_email": "Mikhail Edoshin <mikhail.edoshin@mail.ru>",
"download_url": "https://files.pythonhosted.org/packages/a3/2c/278ce6bd97bacff9a7997a8e946f697243d8cf633862302dafdbf8d07582/pgfm-0.7.3.tar.gz",
"platform": null,
"description": "``pgfm``: a Python client for FileMaker Server Web APIs\n============================================================\n\n:version: ``pgfm`` 0.7.3, July 25, 2023.\n:contact: Mikhail Edoshin\n\nThe |pgfm| module is a Python client for |FileMaker|_ Server Web APIs. It aims to support all FileMaker APIs in a unified and transparent manner.\n\n.. warning:: This is a work in progress. The current version supports the XML \n API, both old and new formats. It does not yet fully support container \n fields, and layout information in ``FMPXMLLAYOUT`` format and the whole \n Data API. Another thing in progress are user and developer documentation.\n\nSample usage\n------------\n\nA FileMaker server at ``http://fm.example.com`` hosts a file **Sample** with toy orders:\n\n.. figure:: https://github.com/MikhailEdoshin/pgfm/raw/main/res/figure-1.png\n :scale: 75\n\n The schema of the **Sample** file and a layout to fetch data.\n\nWe need to write backend code that receives a customer ID, requests all orders of that customer from FileMaker along with their most recent event, and returns them back to the caller as a JSON object with the following structure::\n\n { type: \"customerOrders\" customerId\n orders: [\n { orderId statusTime statusName\n items: [\n { productId productName price quantity } ] } ] }\n\nTo support that a FileMaker developer added a layout **Web.Orders**. The layout does a good half of the work to shape the result: it defines the fields that will be returned and arranges things so that the fields from the **Event** table show the most recent event. \n\nTo use the layout the backend needs send a search request to this layout, get back the result, and process the data to rearrange them as required. With |Pgfm| the simplest way to achieve that would look so:\n\n.. _snippet:\n\n.. code:: Python\n\n import pgfm\n\n def customerOrders(customerId):\n # -> customerId: customer ID, int.\n # <- result, list, JSON-compatible.\n res = dict(type=\"customerOrders\", customerId=customerId, orders=[])\n usr = pgfm.User(\"username\", \"********\")\n srv = pgfm.Srv(\"https://fm.example.com/\", usr)\n req = pgfm.ReqLaySel() \\\n .db(\"Sample\") \\\n .lay(\"Web.Orders\") \\\n .col(\"customerId\", customerId) \\\n .sort(\"Event::time\", \"descend\")\n for rec in srv.send(req).read():\n order = dict(\n orderId = rec.col(\"id\"),\n statusTime = rec.col(\"Event::time\").toPyDatetime().isoformat(),\n statusName = rec.col(\"Event::type\"),\n items = [])\n res.orders.append(order)\n for row in rec.rel(\"OrderItem\"):\n order.items.append(dict(\n productId = row.col(\"productId\"),\n productName = row.col(\"Product::name\"),\n price = row.col(\"Product::price\"),\n quantity = row.col(\"quantity\")))\n return res\n\nThe ``res`` is the resulting object. The ``usr`` is the account we use to send the request and ``srv`` is the FileMaker server. The ``req`` is a request: something like a form that describes the desired action. Here we are going to ask the server to search for records (``ReqLaySel``) and specify the necessary details: file, layout and search criteria.\n\nWe also specify we want to get the results sorted by the **Event::time** field. Although the layout is set up to show the last event, the sort command will sort the orders by their first event. In our case it is fine, but generally it is one of specific FileMaker things one has to intimately understand.\n\nWe send the request to the server and immediately read the response. The result is an iterable of records so we also immediately start iterating over them. If something goes wrong with an HTTP request or a FileMaker response the code will automatically raise an exception.\n\nFor each record we create a new ``dict`` (``order``) and fill it with data from the record\u2019s fields. The module reads FileMaker field values as string-like objects that can be safely used in any string context. By default they will be formatted according to FileMaker rules: for example, a date would come out as ``M/D/Y``. They are not really strings though; they know their specific type and expose methods to correctly convert their values into other representations. In our case we want to format the timestamps according to ISO 8601, so we convert them first to a Python ``datetime`` and then format the result with ``isoformat()``.\n\nWe also add a list for order items. Then we get a portal to the **OrderItem** table, loop through its rows, for each row create another ``dict`` and immediately place it into the ``items`` list.\n\nIn the end we return the result. We used only ``list`` and ``dict`` instances and FileMaker values are strings, so the result can be safely serialized into JSON. \n\nLicense\n-------\n\nThe module is available under the MIT license. The data used for the examples in the documentation are dervied from a sample database from |Contoso|_.\n\nUsage\n-----\n\nThe module uses third-party libraries ``lxml`` and ``requests``. The source code is available on GitHub_. The author, Mikhail Edoshin, can be reached there or via email: one_, another_.\n\n.. _GitHub: https://github.com/MikhailEdoshin/pgfm/\n.. _one: mikhail.edoshin@proofgeist.com\n.. _another: mikhail.edoshin@mail.ru\n\nDevelopment\n-----------\n\nThe project contains the following files::\n\n /\n |_ LICENSE -- licence (MIT)\n |_ Makefile -- Makefile; run 'make' to see help\n |_ README.rst -- The 'README' file (this one)\n |_ pyproject.toml -- Python package specification\n |_ requirements.txt -- Python requirements.\n |_ res\\\n | |_ figure-1.png -- resources for 'README'\n |_ src\\\n | |_ pgfm.py -- the module\n |_ tests\\\n |_ test.py -- tests\n\n\nUse ``Makefile`` to set up the virtual environment for interactive use and tests. The Python package is built with ``flit``.\n\n.. References\n\n.. |Contoso| replace:: one of Microsoft projects (licensed under MIT)\n.. _Contoso: https://github.com/microsoft/Windows-appsample-customers-orders-d\n atabase\n\n.. |FileMaker| replace:: FileMaker\n.. _FileMaker: https://www.claris.com/filemaker/\n\n.. |Pgfm| replace:: ``pgfm``\n\n.. |Pip| replace:: ``pip``\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Python client for FileMaker Web APIs.",
"version": "0.7.3",
"project_urls": null,
"split_keywords": [
"filemaker"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "6eef7656f819a380bba1f03434188401d628fa4cbf9a5b18e0f00e3294c402c6",
"md5": "ea484ed4adb9db9963ae282fb774556f",
"sha256": "63b880f577cd85563389d3fbf21bbb437795dad2a8ecbe9af071bf164b5f1f35"
},
"downloads": -1,
"filename": "pgfm-0.7.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ea484ed4adb9db9963ae282fb774556f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 33529,
"upload_time": "2024-07-25T13:27:26",
"upload_time_iso_8601": "2024-07-25T13:27:26.304040Z",
"url": "https://files.pythonhosted.org/packages/6e/ef/7656f819a380bba1f03434188401d628fa4cbf9a5b18e0f00e3294c402c6/pgfm-0.7.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a32c278ce6bd97bacff9a7997a8e946f697243d8cf633862302dafdbf8d07582",
"md5": "7772ae7553a36982eba310183e9a7ae2",
"sha256": "62014b07269994781d9a07d6e09fa91a7016fe13da351fd46503b8692051e8b9"
},
"downloads": -1,
"filename": "pgfm-0.7.3.tar.gz",
"has_sig": false,
"md5_digest": "7772ae7553a36982eba310183e9a7ae2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 102755,
"upload_time": "2024-07-25T13:27:28",
"upload_time_iso_8601": "2024-07-25T13:27:28.875867Z",
"url": "https://files.pythonhosted.org/packages/a3/2c/278ce6bd97bacff9a7997a8e946f697243d8cf633862302dafdbf8d07582/pgfm-0.7.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-25 13:27:28",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "pgfm"
}