Skip to main content

TypePigeon

tests codecov build version Anaconda-Server Badge License: GPL v3 style

TypePigeon is a Python type converter focused on converting values between various Python data types.

pip install typepigeon

Features

  • convert values directly from one Python type to another with to_type()
  • convert values to JSON format with to_json()
  • convert generic aliases (List[str]) to simple collection types ([str]) with subscripted_type()

Usage

With TypePigeon, you can convert simple values from one type to another:

to_type()

import typepigeon

typepigeon.to_type(0.55, str)
'0.55'

typepigeon.to_type(1, float)
1.0

typepigeon.to_type([1], str)
'[1]'

Additionally, you can also cast values into a collection:

import typepigeon

typepigeon.to_type([1, 2.0, '3'], [int])
[1, 2, 3]

typepigeon.to_type('[1, 2, 3]', (int, str, float))
[1, '2', 3.0]

typepigeon.to_type({'a': 2.5, 'b': 4, 3: '18'}, {str: float})
{'a': 2.5, 'b': 4.0, '3': 18.0}

Some commonly-used classes such as datetime and CRS are also supported:

from datetime import datetime, timedelta

from pyproj import CRS
import typepigeon

typepigeon.to_type(datetime(2021, 3, 26), str)
'2021-03-26 00:00:00'

typepigeon.to_type('20210326', datetime)
datetime(2021, 3, 26)

typepigeon.to_type('01:13:20:00', timedelta)
timedelta(days=1, hours=13, minutes=20, seconds=0)

typepigeon.to_type(timedelta(hours=1), str)
'01:00:00.0'

typepigeon.to_type(timedelta(hours=1), int)
3600

typepigeon.to_type(CRS.from_epsg(4326), int)
4326

typepigeon.to_type(CRS.from_epsg(4326), str)
'GEOGCRS["WGS 84",ENSEMBLE["World Geodetic System 1984 ensemble",MEMBER["World Geodetic System 1984 (Transit)"],MEMBER["World Geodetic System 1984 (G730)"],MEMBER["World Geodetic System 1984 (G873)"],MEMBER["World Geodetic System 1984 (G1150)"],MEMBER["World Geodetic System 1984 (G1674)"],MEMBER["World Geodetic System 1984 (G1762)"],ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["Horizontal component of 3D system."],AREA["World."],BBOX[-90,-180,90,180]],ID["EPSG",4326]]'

typepigeon.to_type(4326, CRS)
CRS.from_epsg(4326)

to_json()

from datetime import datetime

import typepigeon

typepigeon.to_json(5)
5

typepigeon.to_json('5')
'5'

typepigeon.to_json(datetime(2021, 3, 26))
'2021-03-26 00:00:00'

typepigeon.to_json([5, '6', {3: datetime(2021, 3, 27)}])
[5, '6', {3: '2021-03-27 00:00:00'}]

typepigeon.to_json({'test': [5, '6', {3: datetime(2021, 3, 27)}]})
{'test': [5, '6', {3: '2021-03-27 00:00:00'}]}

subscripted_type()

import typepigeon.types
from typing import Dict, List, Tuple

import typepigeon

typepigeon.types.subscripted_type(List[str])
[str]

typepigeon.types.subscripted_type(Dict[str, float])
{str: float}

typepigeon.types.subscripted_type({str: (Dict[int, str], str)})
{str: ({int: str}, str)}

Metadata

Release files for typepigeon 2.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for typepigeon 2.0.4
File Size Uploaded Provenance Actions
typepigeon-2.0.4.tar.gz 40.3 kB Without provenance Details for typepigeon-2.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for typepigeon 2.0.4
File Interpreter ABI Platform Actions
typepigeon-2.0.4-py3-none-any.whl Python 3 none any Details for typepigeon-2.0.4-py3-none-any.whl

Total release size: 72.2 kB

Release files / typepigeon-2.0.4.tar.gz

Download URL typepigeon-2.0.4.tar.gz
Size 40.3 kB
Tags Source
SHA-256 checksum
How to use checksums
279c08f017f7841a0a06a4d411dbee10f3940972549f6863e0ad2b331e021b95
BLAKE2b-256 checksum
How to use checksums
56002b15ea6cf40393dc390f4c5ca280b643dac3bbfe0b71a70d17b752d691f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Release files / typepigeon-2.0.4-py3-none-any.whl

Download URL typepigeon-2.0.4-py3-none-any.whl
Size 31.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c14f406f4282c49ca9dc71b4dbd2afab44bef601365f254b8795ed88ee084c82
BLAKE2b-256 checksum
How to use checksums
fc42a9bd774270272df4b14a2e5a9ae67eee4d2c3db2990a08b576391c4fc692
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Security for typepigeon 2.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page