{"id":24297046,"url":"https://github.com/jayclassless/basicserial","last_synced_at":"2026-02-04T03:35:40.947Z","repository":{"id":57414092,"uuid":"136734825","full_name":"jayclassless/basicserial","owner":"jayclassless","description":"A convenience wrapper around serialization libraries to handle common tasks.","archived":false,"fork":false,"pushed_at":"2022-10-30T01:02:51.000Z","size":53,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-17T17:13:17.866Z","etag":null,"topics":["json","python","serialization","toml","yaml"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jayclassless.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE.rst","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-09T15:23:26.000Z","updated_at":"2022-11-03T18:28:58.000Z","dependencies_parsed_at":"2022-08-26T20:31:13.131Z","dependency_job_id":null,"html_url":"https://github.com/jayclassless/basicserial","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayclassless%2Fbasicserial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayclassless%2Fbasicserial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayclassless%2Fbasicserial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayclassless%2Fbasicserial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jayclassless","download_url":"https://codeload.github.com/jayclassless/basicserial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234261671,"owners_count":18804583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","python","serialization","toml","yaml"],"created_at":"2025-01-16T19:49:59.969Z","updated_at":"2026-02-04T03:35:40.883Z","avatar_url":"https://github.com/jayclassless.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"***********\nbasicserial\n***********\n\n.. image:: https://img.shields.io/pypi/v/basicserial.svg\n   :target: https://pypi.python.org/pypi/basicserial\n.. image:: https://img.shields.io/pypi/l/basicserial.svg\n   :target: https://pypi.python.org/pypi/basicserial\n.. image:: https://github.com/jayclassless/basicserial/workflows/Test/badge.svg\n   :target: https://github.com/jayclassless/basicserial/actions\n\n.. contents:: Contents\n\n\nOverview\n========\nDoes this look familiar?\n\n::\n\n    \u003e\u003e\u003e import json\n    \u003e\u003e\u003e from datetime import date\n    \u003e\u003e\u003e MY_DATA = {'foo': 123, 'bar': date(2018, 5, 22)}\n    \u003e\u003e\u003e json.dumps(MY_DATA)\n    Traceback (most recent call last):\n        ...\n    TypeError: datetime.date(2018, 5, 22) is not JSON serializable\n\nIt's one thing when your serialization tools don't know how to handle your\ncustom classes, but it's annoying when they don't handle the built-in and/or\ncommon data types. Thus, ``basicserial`` was born.\n\nThis package is a thin wrapper around the common serialization tools that can\ndo the following for you when working with JSON, YAML, and TOML:\n\n* Automatically serializes the following types to common-sense representations:\n\n  .. list-table::\n     :header-rows: 1\n\n     * - Type\n       - JSON\n       - YAML\n       - TOML\n     * - `set \u003chttps://docs.python.org/3/library/stdtypes.html#set\u003e`_\n       - array\n       - sequence\n       - array\n     * - `frozenset \u003chttps://docs.python.org/3/library/stdtypes.html#frozenset\u003e`_\n       - array\n       - sequence\n       - array\n     * - `Decimal \u003chttps://docs.python.org/3/library/decimal.html\u003e`_\n       - number\n       - float\n       - float\n     * - `Fraction \u003chttps://docs.python.org/3/library/fractions.html\u003e`_\n       - string\n       - string\n       - string\n     * - `date \u003chttps://docs.python.org/3/library/datetime.html#date-objects\u003e`_\n       - string (ISO 8601)\n       - timestamp\n       - string (ISO 8601)\n     * - `time \u003chttps://docs.python.org/3/library/datetime.html#time-objects\u003e`_\n       - string (ISO 8601)\n       - string (ISO 8601)\n       - string (ISO 8601)\n     * - `datetime \u003chttps://docs.python.org/3/library/datetime.html#datetime-objects\u003e`_\n       - string (ISO 8601)\n       - timestamp\n       - string (ISO 8601)\n     * - `complex \u003chttps://docs.python.org/3/library/functions.html#complex\u003e`_\n       - string\n       - string\n       - string\n     * - `OrderedDict \u003chttps://docs.python.org/3/library/collections.html#collections.OrderedDict\u003e`_\n       - object\n       - map\n       - key/value\n     * - `defaultdict \u003chttps://docs.python.org/3/library/collections.html#defaultdict-objects\u003e`_\n       - object\n       - map\n       - key/value\n     * - `namedtuple \u003chttps://docs.python.org/3/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields\u003e`_\n       - object\n       - map\n       - key/value\n     * - `UserDict \u003chttps://docs.python.org/3/library/collections.html#userdict-objects\u003e`_\n       - object\n       - map\n       - key/value\n     * - `UserList \u003chttps://docs.python.org/3/library/collections.html#userlist-objects\u003e`_\n       - array\n       - sequence\n       - array\n     * - `UserString \u003chttps://docs.python.org/3/library/collections.html#userstring-objects\u003e`_\n       - string\n       - string\n       - string\n     * - `UUID \u003chttps://docs.python.org/3/library/uuid.html#uuid.UUID\u003e`_\n       - string\n       - string\n       - string\n\n* Can serialize `Enum \u003chttps://docs.python.org/3/library/enum.html\u003e`_ members\n  appropriately based on their type.\n\n* Can automatically deserialize dates, times, and datetimes into the native\n  Python objects.\n\n* Provides a simple flag for generating \"pretty\" strings.\n\n\nUsage\n=====\nTo use this package, install it from PyPI (``pip install basicserial``). Then,\nmake sure you install the serialization package you'd like ``basicserial`` to\nuse:\n\n* For YAML, it supports `PyYAML \u003chttps://pypi.org/project/PyYAML\u003e`_ and\n  `ruamel.yaml \u003chttps://pypi.org/project/ruamel.yaml\u003e`_.\n* For TOML, it supports `toml \u003chttps://pypi.org/project/toml\u003e`_, `pytoml\n  \u003chttps://pypi.org/project/pytoml\u003e`_, `qtoml\n  \u003chttps://pypi.org/project/qtoml\u003e`_, `tomlkit\n  \u003chttps://pypi.org/project/tomlkit\u003e`_, and `tomli\n  \u003chttps://pypi.org/project/tomli\u003e`_/`tomli-w \u003chttps://pypi.org/project/tomli_w\u003e`_.\n* For JSON, it supports Python's built-in `json\n  \u003chttps://docs.python.org/3/library/json.html\u003e`_ module, `simplejson\n  \u003chttps://pypi.org/project/simplejson\u003e`_, `orjson\n  \u003chttps://pypi.org/project/orjson\u003e`_, `rapidjson\n  \u003chttps://pypi.org/project/python-rapidjson\u003e`_, `ujson\n  \u003chttps://pypi.org/project/ujson\u003e`_, `hyperjson\n  \u003chttps://pypi.org/project/hyperjson\u003e`_, and `pysimdjson\n  \u003chttps://pypi.org/project/pysimdjson\u003e`_.\n\n``basicserial`` will automatically find a package to use, but if you want to\nuse a specific one, you can specify its name via the ``pkg`` argument to the\nfunctions.\n\nJSON::\n\n    \u003e\u003e\u003e print(basicserial.to_json(MY_DATA))\n    {\"foo\": 123, \"bar\": \"2018-05-22\"}\n\n    \u003e\u003e\u003e print(basicserial.to_json(MY_DATA, pretty=True))\n    {\n      \"foo\": 123,\n      \"bar\": \"2018-05-22\"\n    }\n\n    \u003e\u003e\u003e basicserial.from_json(basicserial.to_json(MY_DATA))\n    {u'foo': 123, u'bar': datetime.date(2018, 5, 22)}\n\n    \u003e\u003e\u003e basicserial.from_json(basicserial.to_json(MY_DATA), native_datetimes=False)\n    {u'foo': 123, u'bar': u'2018-05-22'}\n\n\nYAML::\n\n    \u003e\u003e\u003e print(basicserial.to_yaml(MY_DATA))\n    {bar: 2018-05-22, foo: 123}\n\n    \u003e\u003e\u003e print(basicserial.to_yaml(MY_DATA, pretty=True))\n    bar: 2018-05-22\n    foo: 123\n\n    \u003e\u003e\u003e basicserial.from_yaml(basicserial.to_yaml(MY_DATA))\n    {u'foo': 123, u'bar': datetime.date(2018, 5, 22)}\n\n    \u003e\u003e\u003e basicserial.from_yaml(basicserial.to_yaml(MY_DATA), native_datetimes=False)\n    {'foo': 123, 'bar': u'2018-05-22'}\n\n\nTOML::\n\n    \u003e\u003e\u003e print(basicserial.to_toml(MY_DATA))\n    foo = 123\n    bar = \"2018-05-22\"\n\n    \u003e\u003e\u003e print(basicserial.to_toml(MY_DATA, pretty=True))\n    foo = 123\n    bar = \"2018-05-22\"\n\n    \u003e\u003e\u003e basicserial.from_toml(basicserial.to_toml(MY_DATA))\n    {u'foo': 123, u'bar': datetime.date(2018, 5, 22)}\n\n    \u003e\u003e\u003e basicserial.from_toml(basicserial.to_toml(MY_DATA), native_datetimes=False)\n    {u'foo': 123, u'bar': u'2018-05-22'}\n\n\nLicense\n=======\nThis project is released under the terms of the `MIT License`_.\n\n.. _MIT License: https://opensource.org/licenses/MIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjayclassless%2Fbasicserial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjayclassless%2Fbasicserial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjayclassless%2Fbasicserial/lists"}