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.1.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.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: strast-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 db8f6fb784c50fb0afd2642be83006e966901e635d637a5e576178743622e3c0
MD5 ca18d9ec19b686af27b188ed8a0e30be
BLAKE2b-256 d756d7a0ddb6e9f017d0aeb0d0666cbee907bda65f35d108c1f8fdc632bf4205

See more details on using hashes here.

File details

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

File metadata

  • Download URL: strast-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 455326e203e14e1006559bbf463606612df294d3703eaf2ad0bcfb842ad9d5a2
MD5 9417fbdbd645472adc688ae36bfb6e3d
BLAKE2b-256 64ad1e41af98655a4ee28058ffddaf2ccefbdc6e6f524a2678840f46ba49e73b

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