Skip to main content

Simple OSRM routing and Folium map drawing toolkit

Project description

cartons

A small Python toolkit for routing and map visualization.

cartons calculates routes using OSRM (via routingpy) and renders them on an interactive Leaflet map using folium.

With only a few lines of code you can compute a route between two coordinates and generate an HTML map displaying the route.

The library is designed to be simple, lightweight, and easy to integrate into scripts or small projects.


Demo

Live demo:

https://router.project-osrm.org

This public OSRM server is used in the examples to calculate routes.


Features

  • Simple interface for route calculation
  • Interactive map rendering
  • Uses the OSRM routing engine
  • Lightweight with minimal dependencies
  • Generates shareable HTML maps

Installation

cartons is available on PyPI.

Install from PyPI

pip install cartons

Install from source

git clone https://github.com/yourname/cartons.git
cd cartons
pip install -e .

Dependencies

  • routingpy
  • folium

These will be installed automatically when installing the package.


Quick Example

import cartons

m = cartons.draw(
    "https://router.project-osrm.org",
    8.5417, 47.3769,
    8.55, 47.38
)

m.save("route.html")

This generates an interactive HTML map showing the calculated route.

Open the generated file in a browser to view the map.


Project Structure

cartons/
├── routing.py
├── display.py
└── __init__.py

routing.py

Handles communication with the OSRM routing engine using routingpy.

It sends coordinates to the routing server and returns the routing response.


display.py

Responsible for rendering the route on a Leaflet map using folium.

OSRM returns coordinates in the format:

[lon, lat]

Since Folium expects [lat, lon], the coordinates are converted before drawing the route.


Public OSRM Server

Examples use the public OSRM demo server:

https://router.project-osrm.org

This server is suitable for:

  • testing
  • small scripts
  • experimentation

For production use, running your own OSRM server is recommended.


API

draw(base_url, lon1, lat1, lon2, lat2, col="blue", weight=5)

Calculate a route and return a folium.Map object.

Parameters

Parameter Description
base_url OSRM server URL
lon1 Start longitude
lat1 Start latitude
lon2 Destination longitude
lat2 Destination latitude
col Route color
weight Line thickness

Returns

folium.Map

Goals

cartons aims to provide:

  • a simple routing interface
  • quick map visualization
  • minimal dependencies
  • easy integration into Python scripts

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cartons-1.0.4.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cartons-1.0.4-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file cartons-1.0.4.tar.gz.

File metadata

  • Download URL: cartons-1.0.4.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cartons-1.0.4.tar.gz
Algorithm Hash digest
SHA256 3a08d4c630789009af1ed3df68257176ea366247c670a27bbcf87e077698ec56
MD5 26e5c047a5c90d58ba711aa9086835b3
BLAKE2b-256 a1f2d96e6e10296a9591e70e8b3e52410e9c0e6f8ee1b90ee5eb9ecb3901a63c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartons-1.0.4.tar.gz:

Publisher: python-publish.yml on AndPan3/cartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cartons-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: cartons-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cartons-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b2311124ce50d81423a86ec1e90e91f09c7318b12eafaf61e9f193dbccc8f5d4
MD5 0c99c11d87ccfb163419c806737fc0b9
BLAKE2b-256 13c95acec7219728b7103c4aa8000db1396c47597379ad0e59d397e057b326bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartons-1.0.4-py3-none-any.whl:

Publisher: python-publish.yml on AndPan3/cartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page