ugrc-palletjack


Nameugrc-palletjack JSON
Version 4.3.1 PyPI version JSON
download
home_pagehttps://github.com/agrc/palletjack
SummaryUpdating AGOL feature services with data from external tables.
upload_time2024-04-01 22:56:45
maintainerNone
docs_urlNone
authorJake Adams, UGRC
requires_pythonNone
licenseNone
keywords gis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # agrc/palletjack

![Build Status](https://github.com/agrc/palletjack/workflows/Build%20and%20Test/badge.svg)
[![codecov](https://codecov.io/gh/agrc/palletjack/branch/main/graph/badge.svg)](https://codecov.io/gh/agrc/palletjack)

A library of classes and methods for automatically updating AGOL feature services with data from several different types of external sources. Client apps (sometimes called 'skids') can reuse these classes for common use cases. The code modules are oriented around each step in the extract, transform, and load process.

`palletjack` works with pandas DataFrames (either regular for tabular data or Esri's spatially-enabled dataframes for spatial data). The extract and transform methods return dataframes and the load methods consume dataframes as their source data.

The [documentation](https://agrc.github.io/palletjack/palletjack) includes a user guide along with an API description of the available classes and methods.

Pallet jack: [forklift's](https://www.github.com/agrc/forklift) little brother.

## Dependencies

`palletjack` relies on the dependencies listed in `setup.py`. These are all available on PyPI and can be installed in most environments, including Google Cloud Functions.

The `arcgis` library does all the heavy lifting for spatial data. If the `arcpy` library is not available (such as in a cloud function), it relies on `shapely` for its geometry engine.

## Installation

1. Activate your application's environment
1. `pip install ugrc-palletjack`

## Quick start

1. Import the desired modules
1. Use a class in `extract` to load a dataframe from an external source
1. Transform your dataframe as desired with helper methods from `transform`
1. Use the dataframe to update a hosted feature service using the methods in `load`

   ```python
   from palletjack import extract, transform, load

   #: Load the data from a Google Sheet
   gsheet_extractor = extract.GSheetLoader(path_to_service_account_json)
   sheet_df = gsheet_extractor.load_specific_worksheet_into_dataframe(sheet_id, 'title of desired sheet', by_title=True)

   #: Convert the data to points using lat/long fields, clean for uploading
   spatial_df = pd.DataFrame.spatial.from_xy(input_df, x_column='longitude', y_column='latitude')
   renamed_df = transform.DataCleaning.rename_dataframe_columns_for_agol(spatial_df)
   cleaned_df = transform.DataCleaning.switch_to_nullable_int(renamed_df, ['an_int_field_with_null_values'])

   #: Truncate the existing feature service data and load the new data
   gis = arcgis.gis.GIS('my_agol_org_url', 'username', 'super-duper-secure-password')
   updates = palletjack.load.FeatureServiceUpdater.truncate_and_load_features(
      gis, 'feature_service_item_id', cleaned_df, r'c:\directory\to\save\truncated\data\in\case\of\error'
   )
   ```

## Development

1. Create a conda environment with Python 3.9
   - `conda create -n palletjack python=3.9`
   - `activate palletjack`
1. Clone the repo
1. Install in dev mode with development dependencies
   - `pip install -e .[tests]`

### Troubleshooting Weird Append Errors

If a `FeatureLayer.append()` call (within a load.FeatureServiceUpdater method) fails with an "Unknown Error: 500" error or something like that, you can query the results to get more info. The `urllib3` debug-level logs will include the HTTP GET or POST call, something like the following:
`https://services1.arcgis.com:443 POST /<unique string>/arcgis/rest/services/<feature layer name>/FeatureServer/<layer id>/append/jobs/<job guid>?f=json token=<crazy long token string>`. The defualt `basicConfig` logger includes the `urllib3` logs (`logging.basicConfig(level=logging.DEBUG)`) and is great for development debugging, or you can add a specific logger for `urllib3` in your code and set it's level to debug.  

You can use this and a token from an AGOL tab to build a new job status url. To get the token, log into AGOL in a browser and open a private hosted feature layer item. Click the layer, and then open the developer console. With the Network tab of the console open, click on the "View" link for the service URL. You should see a document in the list whose name includes "?token=<really long token string>". Copy the name and then copy out the token string.

Now that you've got the token string, you can build the status query:
`https://services1.arcgis.com/<unique string>/arcgis/rest/services/<feature layer name>/FeatureServer/<layer id>/append/jobs/<job guid>?f=json&<token from agol>`

Calling this URL in a browser should return a message that will hopefully give you more info as to why it failed.

### Updating Docs

palletjack uses `pdoc3` to generate HTML docs in `docs/palletjack` from the docstrings within the code itself. These are then served up via github pages.

The github pages are served from the `gh-pages` branch. After you make edits to the code and update the docstrings, rebase this branch onto the updated `main` branch. To prevent github pages from trying to generate a site from the contents of `docs/palletjack` with jekyll, add a `.nojekyll` file to `docs/palletjack`.

To generate the docs, run `pdoc --html -o docs\ c:\palletjack\repo\src\palletjack --force`. The code's docstrings should be Google-style docstrings with proper indentation to ensure the argument lists, etc are parsed and displayed correctly.

`docs/README.md` is included at the top package level by adding the line `.. include:: ../../docs/README.md` in `__init__.py`'s docstring. This tells pdoc to insert that markdown into the HTML generated for that docstring, and the include directive can be used for more in-depth documentation anywhere else as well. Note that `pdoc` tries to create links for anything surrounded by backticks, which are also used for code blocks. You may need to manually edit the HTML to remove the links if they change the content of your code blocks (such as in the example import statement).

Once the contents of `docs/palletjack` look correct, force push the `gh-pages` branch to github. This will trigger the action to republish the site. The docs are then accessible at [agrc.github.io/palletjack/palletjack/index.html].

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/agrc/palletjack",
    "name": "ugrc-palletjack",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "gis",
    "author": "Jake Adams, UGRC",
    "author_email": "jdadams@utah.gov",
    "download_url": "https://files.pythonhosted.org/packages/11/2c/e5fad2e84563ed35d0f72d5aa626c50ebbb42ec845b2f1b35c0ca35d9149/ugrc-palletjack-4.3.1.tar.gz",
    "platform": null,
    "description": "# agrc/palletjack\n\n![Build Status](https://github.com/agrc/palletjack/workflows/Build%20and%20Test/badge.svg)\n[![codecov](https://codecov.io/gh/agrc/palletjack/branch/main/graph/badge.svg)](https://codecov.io/gh/agrc/palletjack)\n\nA library of classes and methods for automatically updating AGOL feature services with data from several different types of external sources. Client apps (sometimes called 'skids') can reuse these classes for common use cases. The code modules are oriented around each step in the extract, transform, and load process.\n\n`palletjack` works with pandas DataFrames (either regular for tabular data or Esri's spatially-enabled dataframes for spatial data). The extract and transform methods return dataframes and the load methods consume dataframes as their source data.\n\nThe [documentation](https://agrc.github.io/palletjack/palletjack) includes a user guide along with an API description of the available classes and methods.\n\nPallet jack: [forklift's](https://www.github.com/agrc/forklift) little brother.\n\n## Dependencies\n\n`palletjack` relies on the dependencies listed in `setup.py`. These are all available on PyPI and can be installed in most environments, including Google Cloud Functions.\n\nThe `arcgis` library does all the heavy lifting for spatial data. If the `arcpy` library is not available (such as in a cloud function), it relies on `shapely` for its geometry engine.\n\n## Installation\n\n1. Activate your application's environment\n1. `pip install ugrc-palletjack`\n\n## Quick start\n\n1. Import the desired modules\n1. Use a class in `extract` to load a dataframe from an external source\n1. Transform your dataframe as desired with helper methods from `transform`\n1. Use the dataframe to update a hosted feature service using the methods in `load`\n\n   ```python\n   from palletjack import extract, transform, load\n\n   #: Load the data from a Google Sheet\n   gsheet_extractor = extract.GSheetLoader(path_to_service_account_json)\n   sheet_df = gsheet_extractor.load_specific_worksheet_into_dataframe(sheet_id, 'title of desired sheet', by_title=True)\n\n   #: Convert the data to points using lat/long fields, clean for uploading\n   spatial_df = pd.DataFrame.spatial.from_xy(input_df, x_column='longitude', y_column='latitude')\n   renamed_df = transform.DataCleaning.rename_dataframe_columns_for_agol(spatial_df)\n   cleaned_df = transform.DataCleaning.switch_to_nullable_int(renamed_df, ['an_int_field_with_null_values'])\n\n   #: Truncate the existing feature service data and load the new data\n   gis = arcgis.gis.GIS('my_agol_org_url', 'username', 'super-duper-secure-password')\n   updates = palletjack.load.FeatureServiceUpdater.truncate_and_load_features(\n      gis, 'feature_service_item_id', cleaned_df, r'c:\\directory\\to\\save\\truncated\\data\\in\\case\\of\\error'\n   )\n   ```\n\n## Development\n\n1. Create a conda environment with Python 3.9\n   - `conda create -n palletjack python=3.9`\n   - `activate palletjack`\n1. Clone the repo\n1. Install in dev mode with development dependencies\n   - `pip install -e .[tests]`\n\n### Troubleshooting Weird Append Errors\n\nIf a `FeatureLayer.append()` call (within a load.FeatureServiceUpdater method) fails with an \"Unknown Error: 500\" error or something like that, you can query the results to get more info. The `urllib3` debug-level logs will include the HTTP GET or POST call, something like the following:\n`https://services1.arcgis.com:443 POST /<unique string>/arcgis/rest/services/<feature layer name>/FeatureServer/<layer id>/append/jobs/<job guid>?f=json token=<crazy long token string>`. The defualt `basicConfig` logger includes the `urllib3` logs (`logging.basicConfig(level=logging.DEBUG)`) and is great for development debugging, or you can add a specific logger for `urllib3` in your code and set it's level to debug.  \n\nYou can use this and a token from an AGOL tab to build a new job status url. To get the token, log into AGOL in a browser and open a private hosted feature layer item. Click the layer, and then open the developer console. With the Network tab of the console open, click on the \"View\" link for the service URL. You should see a document in the list whose name includes \"?token=<really long token string>\". Copy the name and then copy out the token string.\n\nNow that you've got the token string, you can build the status query:\n`https://services1.arcgis.com/<unique string>/arcgis/rest/services/<feature layer name>/FeatureServer/<layer id>/append/jobs/<job guid>?f=json&<token from agol>`\n\nCalling this URL in a browser should return a message that will hopefully give you more info as to why it failed.\n\n### Updating Docs\n\npalletjack uses `pdoc3` to generate HTML docs in `docs/palletjack` from the docstrings within the code itself. These are then served up via github pages.\n\nThe github pages are served from the `gh-pages` branch. After you make edits to the code and update the docstrings, rebase this branch onto the updated `main` branch. To prevent github pages from trying to generate a site from the contents of `docs/palletjack` with jekyll, add a `.nojekyll` file to `docs/palletjack`.\n\nTo generate the docs, run `pdoc --html -o docs\\ c:\\palletjack\\repo\\src\\palletjack --force`. The code's docstrings should be Google-style docstrings with proper indentation to ensure the argument lists, etc are parsed and displayed correctly.\n\n`docs/README.md` is included at the top package level by adding the line `.. include:: ../../docs/README.md` in `__init__.py`'s docstring. This tells pdoc to insert that markdown into the HTML generated for that docstring, and the include directive can be used for more in-depth documentation anywhere else as well. Note that `pdoc` tries to create links for anything surrounded by backticks, which are also used for code blocks. You may need to manually edit the HTML to remove the links if they change the content of your code blocks (such as in the example import statement).\n\nOnce the contents of `docs/palletjack` look correct, force push the `gh-pages` branch to github. This will trigger the action to republish the site. The docs are then accessible at [agrc.github.io/palletjack/palletjack/index.html].\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Updating AGOL feature services with data from external tables.",
    "version": "4.3.1",
    "project_urls": {
        "Homepage": "https://github.com/agrc/palletjack",
        "Issue Tracker": "https://github.com/agrc/palletjack/issues"
    },
    "split_keywords": [
        "gis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c03344e00209cc0374b9eba7c985808c90c220678dbc1d85fea944d017bac03a",
                "md5": "424c98dd4356184b7f2cfb850ff84430",
                "sha256": "6d9a801bd9e108c49bd5343f7219e3f6eb79e389c08f013af02c85abf89ba98e"
            },
            "downloads": -1,
            "filename": "ugrc_palletjack-4.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "424c98dd4356184b7f2cfb850ff84430",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 42801,
            "upload_time": "2024-04-01T22:56:43",
            "upload_time_iso_8601": "2024-04-01T22:56:43.201553Z",
            "url": "https://files.pythonhosted.org/packages/c0/33/44e00209cc0374b9eba7c985808c90c220678dbc1d85fea944d017bac03a/ugrc_palletjack-4.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "112ce5fad2e84563ed35d0f72d5aa626c50ebbb42ec845b2f1b35c0ca35d9149",
                "md5": "0a49ee3c6861060929bf6c2afe2fe20d",
                "sha256": "5c0ef93a597be3478af3b62f1a5ef12f93d1cfc9eb1f4db743e3784e6799d822"
            },
            "downloads": -1,
            "filename": "ugrc-palletjack-4.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0a49ee3c6861060929bf6c2afe2fe20d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 42752,
            "upload_time": "2024-04-01T22:56:45",
            "upload_time_iso_8601": "2024-04-01T22:56:45.448585Z",
            "url": "https://files.pythonhosted.org/packages/11/2c/e5fad2e84563ed35d0f72d5aa626c50ebbb42ec845b2f1b35c0ca35d9149/ugrc-palletjack-4.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-01 22:56:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "agrc",
    "github_project": "palletjack",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "ugrc-palletjack"
}
        
Elapsed time: 0.24975s