Skip to main content

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:
	str = "555-1234"
	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

  1. install the python pacakge pip install fxdc
  2. import fxdc import fxdc
  3. 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 When Defined Its Type Doesn't Need a Key. You Can DIrectly Access All UnTypeHinted Variables By = and :

mylist|list:
	="John"
	=12
	=1000.00
	:
		name="John"
		age=12

OUTPUT

[
	"John",
	12,
	1000.00,
	{
		"name": "John",
		"age": 12
	}
]

List Syntax (Type Hinted)

For TypeHinting In List Syntax You Don't Need To Use | You Can Directly Mention The Type And Follow Up With : and =

mylist|list:
	str="John"
	int=12
	float=1000.00
	dict:
		name="John"
		age=12
	list:
		str="Micheal"
		int=23
		bool=1

OUTPUT

[
	"John",
	12,
	1000.00,
	{
		"name": "John",
		"age": 12
	},
	[
		"Micheal",
		23,
		1
	]
]

Nested Variables

members|list:
	dict:
		name="John"
		age=10
	:
		name="Micheal"
		age = 120

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

You Can Also Put Custom Name For Class

from fxdc import Config

class MyClass:
	def __init__(self, name, age):
		self.name = name
		self.age = age
	def __repr__(self):
		return f"<{self.name}: {self.age}>"

Config.add_class("MyDopeClass", MyClass)

OR

from fxdc import Config

@Config.add_class("MyDopeClass")
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|MyDopeClass:
	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

OR

Add it as a decorator on top of a class

from fxdc import Config

@Config.add_class("MyClass")
class MyClass:
	def __init__(self, name:str):
		self.name = name

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:
	str = "555-1234"
	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

Error

Recursion Error

Incase of recursion error just do the following to increase the recursion limit

from fxdc import Config

Config.set_recursion_limit(10000) #Default is 1000 U Can Increase That

Credits

All Packages Made And Manages by FedxD

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

fxdc-2.2.0a0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

fxdc-2.2.0a0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file fxdc-2.2.0a0.tar.gz.

File metadata

  • Download URL: fxdc-2.2.0a0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for fxdc-2.2.0a0.tar.gz
Algorithm Hash digest
SHA256 b7ca85ce6f272a14cfe0ee0383bf51383d4dbf652341bde74a239ccd57b64610
MD5 0c9e9d0909bc131a3634883a7a9a8e30
BLAKE2b-256 334b77db08e91d35a958fa41a3b0647153ecf1c3ef71dbe929f7e0744caaac05

See more details on using hashes here.

File details

Details for the file fxdc-2.2.0a0-py3-none-any.whl.

File metadata

  • Download URL: fxdc-2.2.0a0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for fxdc-2.2.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0d6da73cb496790f6fcaac96741c8e7673c428335c4e64f7d7c575db23c79cd
MD5 ca6aa77aa0e05ad9ceb97ccf336cdd2f
BLAKE2b-256 eda67d53f58c1d9b6884952334f0533e01e9b4be60fd0a2c56deb539400c1fa0

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