Profile Picture

PyTextBin-0.0.3

pip install PyTextBin-0.0.3

About PyTextBin

PyTextBin is a versatile Python library facilitating seamless conversion between text, binary, JSON, base64, xml and CSV formats with ease.

Installation

You can install textbin through your terminal using pip from PyPI

              pip install pytextbin
            

You can also get the source code by cloning the github repository

              
                git clone https://github.com/Comon-tech/Pytextbin
              
            

More info

Inside the textbin.py, there is a Textbin() class which has the methods:

To begin, import the pytextbin module then create an object from the Textbin() class, which you'll use to access all the methods.
                  
                  # import textbin
                  from pytextbin.pytextbin import Textbin
                  
                  # create textbin_obj instance 
                  textbin_obj = Textbin()
                  
                  
              

Usage

Converting Text and binary

        
        from pytextbin.pytextbin import Textbin

        textbin_obj = Textbin()
    
        # Convert text to binary
        word = "hello"
        converted_word = textbin_obj.to_binary(word)
        print(converted_word) 
        
        #Output: 1101000 1100101 1101100 1101100 1101111
        
        # Convert binary to text
        binary = "1101000 1100101 1101100 1101100 1101111"
        converted_binary = textbin_obj.to_text(binary)
        print(converted_binary)  # Output: hello
        
    

Convert JSON and Base64

        
        # import textbin
        from pytextbin.pytextbin import Textbin
          
        # create textbin_obj instance 
        textbin_obj = Textbin()
    
        # Encode a JSON object to base64
        word = {"foo": "bar"}
        converted_word = textbin_obj.json_to_base64(word)
        print(converted_word)  # Output: eyJmb28iOiAiYmFyIn0=
            
        # Decode a base64 string to a JSON object
        base64_string = "eyJmb28iOiAiYmFyIn0="
        converted_binary = textbin_obj.base64_to_json(base64_string)
        print(converted_binary)  # Output: {'foo': 'bar'}
        
    

Convert JSON and CSV

        
        # import textbin
        from pytextbin.pytextbin import Textbin
          
        # create textbin_obj instance 
        textbin_obj = Textbin()


        # Convert a JSON object to CSV
        json_list = [{ 'id' : 12 , 'name' : 'Collins' }]
        converted = textbin_obj.json_to_csv(json_list)
        print(converted)
       
        #Output
        #id,name
        #12,Collins
      
      
    

Convert JSON and xml

        
        # import textbin
        from pytextbin.pytextbin import Textbin
          
        # create textbin_obj instance 
        textbin_obj = Textbin()

        #convert json to xml
        json_data = { 'id' : 12 , 'name' : 'Collins' }
        converted = textbin_obj.json_to_xml(json_data)
        print(converted)

        #Output <item><id>12</id><name>Collins</name></item>

        #convert xml to  json
        xml_data = "<item><id>12</id><name>Collins</name></item>"
        converted = textbin_obj.xml_to_json(xml_data)
        print(converted)

        #Output { 'id' : 12 , 'name' : 'Collins' }
      
      
    
Add more usage

Get in Touch