This Package Parses FxDC file and returns the object
Project description
FedxD Data Container (FxDC)
Preview
It is used to convert a FxDC string to FxDC object than can be parsed
FxDC String
name|str = "John"
age|int = 23
address|dict:
street|str = "123 Main St"
city|str = "New York"
phone|list:
a|str = "555-1234"
b|str = "555-4567"
It Can be Converted To a FxDC class Object or a Json Supported Dictionary
Converted Json Dictionary
{
"name": "John",
"age": 23,
"address": {
"street": "123 Main St",
"city": "New York"
},
"phone": [
"555-1234",
"555-4567"
]
}
Get Started
- install the python pacakge
pip install fxdc - import fxdc
import fxdc - Enjoy
Syntax
Basic Syntax
name="John"
age=12
salary=1000.00
Type Hinting Syntax
name|str="John"
age|int=12
is_male|bool=1
salary|float=1000.00
Some Types Can Only Be Accessed By Type Hinting Like Bool, List And Custom Classes
MultiLine Variable
mydict:
name|str="John"
age|int=12
Multi Line Variables Without Type Hinting Is a Python Dict. Indentation Is Required to Diffrentiate B/w variables
List Syntax
List Syntax is a Bit More Complicated. The Variable Name is ignored when using list and only the value and type is noted
mylist|list:
a=100
b="john"
c=1203.323
d|bool="False"
Python Output
[100, "john", 1203.323, False]
Nested Variables
members|list:
a|dict:
name="John"
age=10
b:
name="Micheal"
age = 120
Python Output
[
{
"name": "John",
"age": 10
},
{
"name": "Micheal",
"age": 120
}
]
Custom Class Types
Class
class MyClass:
def __init__(self, name, age):
self.name = name
self.age = age
def __repr__(self):
return f"<{self.name}: {self.age}>"
FxDC File
main|MyClass:
name="john"
age=23
In Order To Make Bot Use Custom Class U Need To Add The Class To Config
from fxdc import Config
Config.add_class("MyClass", MyClass) #Name of Class, Class
This Will Ensure The Initializing Of The Class When Loading the FxDC container
You Can Have a to_data() function and from_data() function to get and put information to make the class object. from_data() should be of @staticmethod
class MyClass:
def __init__(self, name, age):
self.name = name
self.age = age
self.salary = age * 2
def __repr__(self):
return f"<{self.name}: {self.age}>"
def to_data(self) -> dict:
return {
"name": self.name,
"age": self.age
}
@staticmethod
def from_data(**kwargs) -> "MyClass":
return MyClass(kwargs["name"], kwargs["age"])
Usage
Converting FxDC to Class Object
From File
import fxdc
fxdcobject = fxdc.load("main.fxdc") #Name of the File
OR
import fxdc
with open("main.fxdc", "w") as f:
fxdcobject = fxdc.load(f)
From String
fxdcstring = """
name|str = "John"
age|int = 23
address|dict:
street|str = "123 Main St"
city|str = "New York"
phone|list:
a|str = "555-1234"
b|str = "555-4567"
"""
from fxdc import loads
fxdcobject = loads(fxdcstring)
Converting Class Object To FxDC
You Can Put Any Type of object to convert to FxDC including strings and custom objects
Class Object
class MyClass:
def __init__(self, name:str, age:int):
self.name = name
self.age = age
def __repr__(self):
return f"{self.name}: {self.age}"
from fxdc import dumps
obj = MyClass("John", 23)
fxdcstring = dumps(obj)
print(fxdcstring)
main|MyClass:
name|str="John"
age|int=20
It Also Inputs The Same Class And Can Auto Convert To That Class
Credits
All Packages Made And Manages by FedxD
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fxdc-0.1.tar.gz
(4.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
fxdc-0.1-py3-none-any.whl
(5.5 kB
view details)
File details
Details for the file fxdc-0.1.tar.gz.
File metadata
- Download URL: fxdc-0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0218b0269e5ff9d51756a3a11b970d9d2dfea5a2326c63a8a02e3e155ed675e8
|
|
| MD5 |
89123e06818018c88abf17477269a24a
|
|
| BLAKE2b-256 |
43094ebb729e3f692c6b6bce4053fe04290672256e81ce39d605c129cb08ceec
|
File details
Details for the file fxdc-0.1-py3-none-any.whl.
File metadata
- Download URL: fxdc-0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf82c2faf4da497483014699a745f355b29db40762bd5c914a001f12822ec8a5
|
|
| MD5 |
865ab2fb9e6438381f85dc38f3cc12ad
|
|
| BLAKE2b-256 |
b00da56884461d6019474ee7b3d205b44172603724dd51c4cf8aa6ecc300fda8
|