OdkCentral¶
Bases: object
Helper methods for ODK Central API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the ODK Central |
None
|
user
|
str
|
The user's account name on ODK Central |
None
|
passwd
|
str
|
The user's account password on ODK Central |
None
|
session
|
str
|
Pass in an existing session for reuse. |
required |
Returns:
Type | Description |
---|---|
OdkCentral
|
An instance of this class |
Source code in osm_fieldwork/OdkCentralAsync.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
authenticate
async
¶
authenticate()
Authenticate to an ODK Central server.
Source code in osm_fieldwork/OdkCentralAsync.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
options: show_source: false heading_level: 3
Bases: OdkCentral
Class to manipulate a project on an ODK Central server.
user (str): The user's account name on ODK Central
passwd (str): The user's account password on ODK Central.
Returns:
Type | Description |
---|---|
OdkProject
|
An instance of this object |
Source code in osm_fieldwork/OdkCentralAsync.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
listForms
async
¶
listForms(projectId, metadata=False)
Fetch a list of forms in a project on an ODK Central server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central |
required |
Returns:
Type | Description |
---|---|
list
|
The list of XForms in this project |
Source code in osm_fieldwork/OdkCentralAsync.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
getAllProjectSubmissions
async
¶
getAllProjectSubmissions(projectId, xforms=None, filters=None)
Fetch a list of submissions in a project on an ODK Central server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central |
required |
xforms
|
list
|
The list of XForms to get the submissions of |
None
|
Returns:
Type | Description |
---|---|
json
|
All of the submissions for all of the XForm in a project |
Source code in osm_fieldwork/OdkCentralAsync.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
options: show_source: false heading_level: 3
Bases: OdkCentral
Class to manipulate a Entity on an ODK Central server.
user (str): The user's account name on ODK Central
passwd (str): The user's account password on ODK Central.
Returns:
Type | Description |
---|---|
OdkDataset
|
An instance of this object. |
Source code in osm_fieldwork/OdkCentralAsync.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
listDatasets
async
¶
listDatasets(projectId)
Get all Entity datasets (entity lists) for a project.
JSON response: [ { "name": "people", "createdAt": "2018-01-19T23:58:03.395Z", "projectId": 1, "approvalRequired": true } ]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
a list of JSON dataset metadata. |
Source code in osm_fieldwork/OdkCentralAsync.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
|
createDataset
async
¶
createDataset(projectId, datasetName='features', properties=[])
Creates a dataset for a given project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project to create the dataset for. |
required |
datasetName
|
str
|
The name of the dataset to be created. |
'features'
|
properties
|
list[str]
|
List of property names to create. Alternatively call createDatasetProperty for each property manually. |
[]
|
Returns:
Name | Type | Description |
---|---|---|
dict |
The JSON response containing information about the created dataset. |
Raises:
Type | Description |
---|---|
ClientError
|
If an error occurs during the dataset creation process. |
Source code in osm_fieldwork/OdkCentralAsync.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
|
createDatasetProperty
async
¶
createDatasetProperty(projectId, field_name, datasetName='features')
Create a property for a dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project. |
required |
datasetName
|
str
|
The name of the dataset. |
'features'
|
field
|
dict
|
A dictionary containing the field information. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
The response data from the API. |
Raises:
Type | Description |
---|---|
ClientError
|
If an error occurs during the API request. |
Source code in osm_fieldwork/OdkCentralAsync.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
|
listEntities
async
¶
listEntities(projectId, datasetName)
Get all Entities for a project dataset (entity list).
JSON format: [ { "uuid": "uuid:85cb9aff-005e-4edd-9739-dc9c1a829c44", "createdAt": "2018-01-19T23:58:03.395Z", "updatedAt": "2018-03-21T12:45:02.312Z", "deletedAt": "2018-03-21T12:45:02.312Z", "creatorId": 1, "currentVersion": { "label": "John (88)", "data": { "field1": "value1" }, "current": true, "createdAt": "2018-03-21T12:45:02.312Z", "creatorId": 1, "userAgent": "Enketo/3.0.4", "version": 1, "baseVersion": null, "conflictingProperties": null } } ]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central. |
required |
datasetName
|
str
|
The name of a dataset, specific to a project. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
a list of JSON entity metadata, for a dataset. |
Source code in osm_fieldwork/OdkCentralAsync.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
|
getEntity
async
¶
getEntity(projectId, datasetName, entityUuid)
Get a single Entity by it's UUID for a project.
JSON response: { "uuid": "a54400b6-49fe-4787-9ab8-7e2f56ff52bc", "createdAt": "2024-04-15T09:26:08.209Z", "creatorId": 5, "updatedAt": null, "deletedAt": null, "conflict": null, "currentVersion": { "createdAt": "2024-04-15T09:26:08.209Z", "current": true, "label": "test entity", "creatorId": 5, "userAgent": "Python/3.10 aiohttp/3.9.3", "data": { "osm_id": "1", "geometry": "test" }, "version": 1, "baseVersion": null, "dataReceived": { "label": "test entity", "osm_id": "1", "geometry": "test" }, "conflictingProperties": null } }
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central. |
required |
datasetName
|
str
|
The name of a dataset, specific to a project. |
required |
entityUuid
|
str
|
Unique itentifier of the entity in the dataset. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
the JSON entity details, for a specific dataset. |
Source code in osm_fieldwork/OdkCentralAsync.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
|
createEntity
async
¶
createEntity(projectId, datasetName, label, data)
Create a new Entity in a project dataset (entity list).
JSON request: { "uuid": "54a405a0-53ce-4748-9788-d23a30cc3afa", "label": "John Doe (88)", "data": { "firstName": "John", "age": "88" } }
JSON response: { "uuid": "d2e03bf8-cfc9-45c6-ab23-b8bc5b7d9aba", "createdAt": "2024-04-12T15:22:02.148Z", "creatorId": 5, "updatedAt": None, "deletedAt": None, "conflict": None, "currentVersion": { "createdAt": "2024-04-12T15:22:02.148Z", "current": True, "label": "test entity 1", "creatorId": 5, "userAgent": "Python/3.10 aiohttp/3.9.3", "data": { "status": "READY", "geometry": "test" }, "version": 1, "baseVersion": None, "dataReceived": { "label": "test entity 1", "status": "READY", "geometry": "test" }, "conflictingProperties": None } }
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central. |
required |
datasetName
|
int
|
The name of a dataset, specific to a project. |
required |
label
|
str
|
Label for the Entity. |
required |
data
|
dict
|
Key:Value pairs to insert as Entity data. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
JSON of entity details. The 'uuid' field includes the unique entity identifier. |
Source code in osm_fieldwork/OdkCentralAsync.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
|
createEntities
async
¶
createEntities(projectId, datasetName, entities)
Bulk create Entities in a project dataset (entity list).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central. |
required |
datasetName
|
int
|
The name of a dataset, specific to a project. |
required |
entities
|
list[EntityIn]
|
A list of Entities to insert. Format: {"label": "John Doe", "data": {"firstName": "John", "age": "22"}} |
required |
Returns:
Name | Type | Description |
---|---|---|
dict
|
list: A list of Entity detail JSONs.¶ |
|
dict
|
The 'uuid' field includes the unique entity identifier.¶ |
|
dict |
dict
|
{'success': true} When creating bulk entities ODK Central return this for now. |
Source code in osm_fieldwork/OdkCentralAsync.py
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
|
updateEntity
async
¶
updateEntity(projectId, datasetName, entityUuid, label=None, data=None, newVersion=None)
Update an existing Entity in a project dataset (entity list).
The JSON request format is the same as creating, minus the 'uuid' field. The PATCH will only update the specific fields specified, leaving the remainder.
If no 'newVersion' param is provided, the entity will be force updated in place. If 'newVersion' is provided, this must be a single integer increment from the current version.
Example response: { "uuid": "71fff014-7518-429b-b97c-1332149efe7a", "createdAt": "2024-04-12T14:22:37.121Z", "creatorId": 5, "updatedAt": "2024-04-12T14:22:37.544Z", "deletedAt": None, "conflict": None, "currentVersion": { "createdAt": "2024-04-12T14:22:37.544Z", "current": True, "label": "new label", "creatorId": 5, "userAgent": "Python/3.10 aiohttp/3.9.3", "data": { "osm_id": "1", "status": "new status", "geometry": "test", "project_id": "100" }, "version": 3, "baseVersion": 2, "dataReceived": { "status": "new status", "project_id": "100" }, "conflictingProperties": None } }
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central. |
required |
datasetName
|
int
|
The name of a dataset, specific to a project. |
required |
entityUuid
|
str
|
Unique itentifier of the entity. |
required |
label
|
str
|
Label for the Entity. |
None
|
data
|
dict
|
Key:Value pairs to insert as Entity data. |
None
|
newVersion
|
int
|
Integer version to increment to (current version + 1). |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
JSON of entity details. The 'uuid' field includes the unique entity identifier. |
Source code in osm_fieldwork/OdkCentralAsync.py
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 |
|
deleteEntity
async
¶
deleteEntity(projectId, datasetName, entityUuid)
Delete an Entity in a project dataset (entity list).
Only performs a soft deletion, so the Entity is actually archived.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central. |
required |
datasetName
|
int
|
The name of a dataset, specific to a project. |
required |
entityUuid
|
str
|
Unique itentifier of the entity. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Deletion successful or not. |
Source code in osm_fieldwork/OdkCentralAsync.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 |
|
getEntityCount
async
¶
getEntityCount(projectId, datasetName)
Get only the count of the Entity entries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central. |
required |
datasetName
|
int
|
The name of a dataset, specific to a project. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
All entity data for a project dataset. |
Source code in osm_fieldwork/OdkCentralAsync.py
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 |
|
getEntityData
async
¶
getEntityData(projectId, datasetName, url_params=None, include_metadata=False)
Get a lightweight JSON of the entity data fields in a dataset.
Be sure to check the latest docs to see which fields are supported for OData filtering: https://docs.getodk.org/central-api-odata-endpoints/#id3
Example response list (include_metadata=False): [ { "__id": "523699d0-66ec-4cfc-a76b-4617c01c6b92", "label": "the_label_you_defined", "__system": { "createdAt": "2024-03-24T06:30:31.219Z", "creatorId": "7", "creatorName": "fmtm@hotosm.org", "updates": 4, "updatedAt": "2024-03-24T07:12:55.871Z", "version": 5, "conflict": null }, "geometry": "javarosa format geometry", "user_defined_field2": "text", "user_defined_field2": "text", "user_defined_field3": "test" } ]
Example response JSON where: - url_params="$top=205&$count=true" - include_metadata=True automatically due to use of $top param
{ "value": [ { "__id": "523699d0-66ec-4cfc-a76b-4617c01c6b92", "label": "the_label_you_defined", "__system": { "createdAt": "2024-03-24T06:30:31.219Z", "creatorId": "7", "creatorName": "fmtm@hotosm.org", "updates": 4, "updatedAt": "2024-03-24T07:12:55.871Z", "version": 5, "conflict": null }, "geometry": "javarosa format geometry", "user_defined_field2": "text", "user_defined_field2": "text", "user_defined_field3": "test" } ] "@odata.context": ( "https://URL/v1/projects/6/datasets/buildings.svc/$metadata#Entities", ) "@odata.nextLink": ( "https://URL/v1/projects/6/datasets/buildings.svc/Entities" "?%24top=250&%24count=true&%24skiptoken=returnedtokenhere%3D" "@odata.count": 667 }
Info on OData URL params: http://docs.oasis-open.org /odata/odata/v4.01/odata-v4.01-part1-protocol.html#_Toc31358948
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projectId
|
int
|
The ID of the project on ODK Central. |
required |
datasetName
|
int
|
The name of a dataset, specific to a project. |
required |
url_params
|
str
|
Any supported OData URL params, such as 'filter' or 'select'. The ? is not required. |
None
|
include_metadata
|
bool
|
Include additional metadata. If true, returns a dict, if false, returns a list of Entities. If $top is included in url_params, this is enabled by default to get the "@odata.nextLink" field. |
False
|
Returns:
Type | Description |
---|---|
dict | list
|
list | dict: All (or filtered) entity data for a project dataset. |
Source code in osm_fieldwork/OdkCentralAsync.py
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 |
|
options: show_source: false heading_level: 3
Usage Example¶
- An async context manager must be used (
async with
).
from osm_fieldwork.OdkCentralAsync import OdkProject
async with OdkProject(
url="http://server.com",
user="user@domain.com",
passwd="password",
) as odk_central:
projects = await odk_central.listProjects()