
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
This library streamlines the process of creating data classes and offers a versatile configuration model. It also enables the dumping and restoration of data. This library is built on Pydantic.
You can add it to your project using the following command:
pip install t-object
After installing, you can import it into your project using the command
from t_object import ThoughtfulObject.
Make sure to check the documentation for detailed usage instructions and examples.
.. code-block:: python
class Driver(ThoughtfulObject):
name: str
age: int
driving_experience: timedelta
last_driving_date: datetime
class Car(ThoughtfulObject):
model: str
car_release_date: date
price: float
driver: list[Driver]
and
.. code-block:: python
class Patient(ThoughtfulObject):
name: str
age: int
birth_date: datetime
.. code-block:: python
car = Car(
model="Tesla Model S",
car_release_date=date(2012, 6, 22),
price=79999.99,
driver=[
Driver(
name="Elon Musk",
age=49,
driving_experience=timedelta(days=365 * 30),
last_driving_date=datetime(2021, 1, 1)
),
Driver(
name="Jeff Bezos",
age=57,
driving_experience=timedelta(days=365 * 20),
last_driving_date=datetime(2021, 1, 1)
)]
)
and
.. code-block:: python
patient = Patient(
name="John Doe",
age=42,
birth_date=datetime(1979, 1, 1)
)
from t_object import ThoughtfulObject. Default configuration listed below... code-block:: python
validate_assignment=True,
extra=Extra.forbid,
frozen=False,
populate_by_name=False,
arbitrary_types_allowed=True,
allow_inf_nan=True,
strict=True,
revalidate_instances=RevalidateInstances.always,
validate_default=False,
coerce_numbers_to_str=True,
validation_error_cause=True,
str_strip_whitespace=True,
build_custom_t_object function. You can find all configuration flags at https://docs.pydantic.dev/2.6/api/config/. Here is how to use it.. code-block:: python
ResponseObject = build_custom_t_object(
extra=Extra.allow,
frozen=True,
allow_inf_nan=True,
strict=False,
)
class UserResponse(ResponseObject):
name: str
age: int
dob: datetime
save_to_json_file() method. You can either define the file path manually or leave it blank for automatic naming.load_from_json_file(file_path: str) class method. This method validates the data against your model automatically. The file_path attribute is required, which is the path to the JSON file... code-block:: python
patient = Patient.load_from_json_file("patient.json")
It is possible to print any instance in a more readable and attractive format. This formatting can be achieved by employing the pretty_string() method. This method allows for the effortless transformation of the raw data into a format that is easier on the eyes,
FAQs
t_object
We found that t-object demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.