Code Monkey home page Code Monkey logo

felt-python's Introduction

The official Python client for the Felt API

PyPI Binder open_in_colab

felt-python is a Python client for the Felt API. It provides convenient wrappers for common operations like creating, deleting and updating maps and data layers.

This client is especially useful at simplifying certain operations like uploading and refreshing files and (Geo)DataFrames or updating layer styles and element properties.

Installation

pip install felt-python

Usage

Authentication

To authenticate with the Felt API, you need to provide your API token. You can either pass it explicitly to function calls or set it in the FELT_API_TOKEN environment variable. Use the Felt dashboard to create a new token.

import os

os.environ["FELT_API_TOKEN"] = "YOUR_API_TOKEN"

Creating a map

from felt_python import create_map

response = create_map(
    title="My new map",
    lat=40,
    lon=-3,
    public_access="private",
)
map_id = response["id"]

Uploading a file

from felt_python import upload_file, list_layers

upload = upload_file(
    map_id=map_id,
    file_name="path/to/file.csv",
    layer_name="My new layer",
)
layer_id = upload["layer_id"]

Uploading a Pandas DataFrame

import pandas as pd
from felt_python import upload_dataframe

df = pd.read_csv("path/to/file.csv")
upload_dataframe(
    map_id=map_id,
    dataframe=df,
    layer_name="Felt <3 Pandas",
)

Uploading a GeoPandas GeoDataFrame

import geopandas as gpd
from felt_python import upload_geodataframe

gdf = gpd.read_file("path/to/file.shp")
upload_geodataframe(
    map_id=map_id,
    geodataframe=gdf,
    layer_name="Felt <3 GeoPandas",
)

Refreshing a layer

from felt_python import refresh_file_layer

refresh_file_layer(
    map_id=map_id,
    layer_id=layer_id,
    file_path="path/to/new_file.csv",
)

Styling a layer

from felt_python import get_layer_details, update_layer_style

current_style = get_layer_details(
    map_id=map_id,
    layer_id=layer_id,
)["style"]
new_style = current_style.copy()
new_style["color"] = "#FF0000"
new_style["size"] = 20
update_layer_style(
    map_id=map_id,
    layer_id=layer_id,
    style=new_style,
)

Support

We are always eager to hear from you. Reach out to [email protected] for all your Felt support needs.

felt-python's People

Contributors

arredond avatar cduruk avatar drewhgood avatar migurski avatar

Stargazers

 avatar Chris Loer avatar  avatar Andrew Desautels avatar Max Schrader avatar Nicolas Collignon avatar  avatar Loren Baxter avatar Ane R V avatar Robert A Fraser avatar Dan Hooke avatar  avatar DougW avatar David Hersh avatar Marc G avatar Cainã avatar

Watchers

Jason Axelson avatar Loren Baxter avatar sukanya avatar Erica Fischer avatar Isaac Besora Vilardaga avatar Tom Hicks avatar Dorgan avatar  avatar

felt-python's Issues

update Load file example

example reads:

upload = upload_file(
    map_id=map_id,
    file_path="path/to/file.csv",
    layer_name="My new layer",
)

should be

upload = upload_file(
    map_id=map_id,
    file_name="path/to/file.csv",
    layer_name="My new layer"
)

updating style returns 422 error

example code

null_island = fp.upload_file(
    map_id = map_id,
    file_name = "null_island.geojson",
    layer_name = "Null Island"
)

ni_layer_id = null_island["layer_id"]

urrent_style = fp.get_layer_details(
    map_id=map_id,
    layer_id=ni_layer_id
)

new_style = current_style.copy()
new_style["color"] = "#FF0000"
new_style["size"] = 60
print("Style: ", new_style)

fp.update_layer_style(
    map_id=map_id,
    layer_id=ni_layer_id,
    style=new_style
)

Returns the following error:

Style:  {'id': 'uBcnG2XRRcG7M9Cc1ercJID', 'links': {'self': '/api/v2/maps/2jX0YV9AXTNeEhIU0Cfge0C/layers/uBcnG2XRRcG7M9Cc1ercJID'}, 'name': 'Null Island', 'status': 'processing', 'type': 'layer', 'progress': 0, 'style': {}, 'geometry_type': None, 'hide_from_legend': False, 'subtitle': '', 'ordering_key': 1, 'color': '#FF0000', 'size': 60}
Traceback (most recent call last):
  File "/Users/sophiaparafina/git/spara/felt/map.py", line 55, in <module>
    fp.update_layer_style(
  File "/Users/sophiaparafina/git/spara/felt/venv/lib/python3.11/site-packages/felt_python/layers.py", line 202, in update_layer_style
    response = make_request(
               ^^^^^^^^^^^^^
  File "/Users/sophiaparafina/git/spara/felt/venv/lib/python3.11/site-packages/felt_python/api.py", line 45, in make_request
    return urllib.request.urlopen(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 563, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 422: Unprocessable Entity

update example create map example

example for creating a map has an error

response = create_map(
    title="My new map",
    lat=40,
    lon=-3,
    public_access="private",
)
map_id = resp["id"]

should be:

map_id = response["id"]

update Upload GeoPandas GeoDataFrame example

wrong parameter name in example:

upload_geodataframe(
    map_id=map_id,
    dataframe=gdf,
    layer_name="Felt <3 GeoPandas",
)

should be:

upload_geodataframe(
    map_id=map_id,
    geodataframe=gdf,
    layer_name="Felt <3 GeoPandas",
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.