Skip to main content
Pydantic Docs
current

Search documentation

Type to search this documentation.

On this pageOverview

Coordinate

The pydantic_extra_types.coordinate module provides the Latitude, Longitude, and Coordinate data types.

Bases: float

Latitude value should be between -90 and 90, inclusive.

Supports both float and Decimal types.

Python
from decimal import Decimal
from pydantic import BaseModel
from pydantic_extra_types.coordinate import Latitude

class Location(BaseModel):
    latitude: Latitude

# Using float
location1 = Location(latitude=41.40338)
# Using Decimal
location2 = Location(latitude=Decimal('41.40338'))

Bases: float

Longitude value should be between -180 and 180, inclusive.

Supports both float and Decimal types.

Python
from decimal import Decimal
from pydantic import BaseModel

from pydantic_extra_types.coordinate import Longitude

class Location(BaseModel):
    longitude: Longitude

# Using float
location1 = Location(longitude=2.17403)
# Using Decimal
location2 = Location(longitude=Decimal('2.17403'))

Bases: Representation

Coordinate parses Latitude and Longitude.

You can use the Coordinate data type for storing coordinates. Coordinates can be defined using one of the following formats:

  1. Tuple: (Latitude, Longitude). For example: (41.40338, 2.17403) or (Decimal('41.40338'), Decimal('2.17403')).
  2. Coordinate instance: Coordinate(latitude=Latitude, longitude=Longitude).
Python
from decimal import Decimal
from pydantic import BaseModel

from pydantic_extra_types.coordinate import Coordinate

class Location(BaseModel):
    coordinate: Coordinate

# Using float values
location1 = Location(coordinate=(41.40338, 2.17403))
# > coordinate=Coordinate(latitude=41.40338, longitude=2.17403)

# Using Decimal values
location2 = Location(coordinate=(Decimal('41.40338'), Decimal('2.17403')))
# > coordinate=Coordinate(latitude=41.40338, longitude=2.17403)
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu