Skip to main content

Transforms a string representation of a Python literal into the corresponding Python object.

Project description

Strast

Strast is a versatile Python tool that transforms a string representation of a Python literal into the corresponding Python object, building upon the powerful ast module. The word "strast" also denotes "passion", reflecting our enthusiasm for data transformation.

Features

  • Transform string literals to Python objects seamlessly with the power of the ast module.
  • Flexible type checking to ensure data integrity.
  • Supports extensibility through factory and class-based approaches.

Installation

To install Strast, use pip:

pip install strast

Usage

import strast

Function

strasts core function:

result = strast.c("{'a': 1, 'b': 2}", dict) # or strast.core.strast
print(result)
print(strast("{'a': 1, 'b': 2}", list))

Output:

{'a': 1, 'b': 2}
TypeError: Expected <class 'list'>, got <class 'dict'> instead.

Factory

strast as a closure factory function:

strast = strast.f(dict, list, tuple) # or strast.factory.strast
print(strast("{'a': 1, 'b': 2}"))
print(strast("[1, 2, 3]"))
print(strast("('a', 'b', 'c')"))

Output:

{'a': 1, 'b': 2}
[1, 2, 3]
('a', 'b', 'c')

Class-based

strast as a class:

strast = strast.S(dict) # or strast.class_based.Strast
print(strast.transform("{'a': 1, 'b': 2}"))

Output:

{'a': 1, 'b': 2}

See also documentation

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

Strast is licensed under the 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

strast-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

strast-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file strast-0.1.0.tar.gz.

File metadata

  • Download URL: strast-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for strast-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ba1cdfa482708b99a3858d06f476401e7ee4d3dec0dff79163b592fa7a5f4cda
MD5 62c96723cf667d0ed895b71f24bf2c19
BLAKE2b-256 b4aa7aa5237cd7195865249cd259ba79b87d3d043ea0a6df2eb0676ffb53c4f9

See more details on using hashes here.

File details

Details for the file strast-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: strast-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for strast-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6590e62e98450bee37f62cb82d49117013a7be592e182c8446312ebb061987f
MD5 29e8969e5adfc2c4810a95ee47b4ac14
BLAKE2b-256 a42429a0628bba5d3ece3a7e9a16eb3eb684649bf5806d733bccfe501105dca5

See more details on using hashes here.

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