Skip to main content

adaptyper

Старается конвертировать один тип данных в другой.

Обработка пользовательских данных из не строго типизированных значений.

from adaptyper import convert, ValueType

# to
convert('FaLsE').to(ValueType.BOOL)  # False
convert('any_str_value').to('bool')  # True
convert(0).to('bool')  # False
convert(1.0).to('bool')  # True

convert(True).to(ValueType.STR)  # "TRUE"
convert(-1).to('str')  # "-1"

convert(True).to(ValueType.FLOAT)  # 1.0
convert('FaLsE').to('float')  # 0.0
convert('.5').to('float')  # 0.5
convert(-1).to('float')  # -1.0

convert(True).to(ValueType.INT)  # 1
convert('1.5').to('int')  # 1
convert('1.5').to('int', True)  # 2

convert('2011-11-04').to(ValueType.DATETIME)  # datetime(2011, 11, 4, 0, 0)
convert('4.11.2011').to('datetime', '%d.%m.%Y')  # datetime(2011, 11, 4, 0, 0)

convert('2011-11-04').to(ValueType.DATE)  # date(2011, 11, 4)
convert('4.11.2011').to('date', '%d.%m.%Y')  # date(2011, 11, 4)

convert('.00').to(ValueType.DECIMAL)  # Decimal('0.00')
convert('.5').to('decimal')  # Decimal('0.5')
convert(-1).to('decimal')  # Decimal('-1')
convert("- 123 \xa0 456").to('decimal')  # Decimal('-123456')

# bool
convert('').to_bool()  # False
convert('0').to_bool()  # False
convert('FaLsE').to_bool()  # False
convert('any_str_value').to_bool()  # True

# str
convert(True).to_str()  # "TRUE"
convert('any_str_value').to_str()  # "any_str_value"
convert(1).to_str()  # "1"
convert(-1).to_str()  # "-1"
convert(123.456).to_str()  # "123.456"
convert(-123.456).to_str()  # "-123.456"

# float
convert(None).to_float()  # None
convert('').to_float()  # None
convert('123,456').to_float()  # 123.456
convert(' 123\xa0456\xa0').to_float()  # 123456.0
convert('tRuE').to_float()  # 1.0
convert(True).to_float()  # 1.0
convert(1).to_float()  # 1.0
convert('.3').to_float()  # 0.3

# int
# работает через float,
# банковское округление (по-умолчанию False)
convert('.6').to_int()  # 0
convert('.6').to_int(bankers_rounding=True)  # 1
convert('1.5').to_int(False)  # 1
convert('1.5').to_int(True)  # 2

# datetime
convert(None).to_datetime()  # None
convert('').to_datetime()  # None
convert('2011-11-04').to_datetime()  # datetime(2011, 11, 4, 0, 0)
convert('4.11.2011').to_datetime('%d.%m.%Y')  # datetime(2011, 11, 4, 0, 0)

# date
# работает через datetime
convert(None).to_date()  # None
convert('').to_date()  # None
convert('2011-11-04').to_date()  # date(2011, 11, 4)
convert('4.11.2011').to_date('%d.%m.%Y')  # date(2011, 11, 4)

# decimal
convert('.00').to(ValueType.DECIMAL)  # Decimal('0.00')
convert('.5').to('decimal')  # Decimal('0.5')
convert(-1).to('decimal')  # Decimal('-1')
convert(123456).to('decimal')  # Decimal('123456')
convert("- 123 456").to('decimal')  # Decimal('-123456')
convert("123\xa0456").to('decimal')  # Decimal('123456')

PyPI Downloads PyPI Downloads PyPI Downloads

Metadata

Release files for adaptyper 0.4.2

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

Source distribution (sdist)

Source distribution for adaptyper 0.4.2
File Size Uploaded Provenance Actions
adaptyper-0.4.2.tar.gz 4.0 kB Without provenance Details for adaptyper-0.4.2.tar.gz

Built distribution (wheel)

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

Total release size: 8.3 kB

Release files / adaptyper-0.4.2.tar.gz

Download URL adaptyper-0.4.2.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
33b60343fc39d44104e67c48f1d23c208beeb6ce52f618e74c577aa96da96174
BLAKE2b-256 checksum
How to use checksums
f3809dc6b568b77f9f837b03cd341f7cee196e56e7f121bcdfc012fc173cb84a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.12.7 Windows/10

Release files / adaptyper-0.4.2-py3-none-any.whl

Download URL adaptyper-0.4.2-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ea901de9a12dd9548828b0c8499fb8eae0e43b9b801bc1268c168cb30118464
BLAKE2b-256 checksum
How to use checksums
ad85d123cc6f6f2ffd766b91f38a2e683e6a603ad4632e4ba00d5bf10c3f4e4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.12.7 Windows/10

Security for adaptyper 0.4.2

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