|
| 1 | +# Msgspec-x |
| 2 | + |
| 3 | + |
1 | 4 | <p align="center"> |
2 | | - <a href="https://jcristharif.com/msgspec/"> |
| 5 | + <a href="https://nightsailer.github.io/msgspec-x/"> |
3 | 6 | <img src="https://raw.githubusercontent.com/jcrist/msgspec/main/docs/source/_static/msgspec-logo-light.svg" width="35%" alt="msgspec" /> |
4 | 7 | </a> |
5 | 8 | </p> |
6 | 9 |
|
7 | 10 | <p align="center"> |
8 | | - <a href="https://github.com/jcrist/msgspec/actions/workflows/ci.yml"> |
9 | | - <img src="https://github.com/jcrist/msgspec/actions/workflows/ci.yml/badge.svg"> |
| 11 | + <a href="https://github.com/nightsailer/msgspec-x/actions/workflows/ci.yml"> |
| 12 | + <img src="https://github.com/nightsailer/msgspec-x/actions/workflows/ci.yml/badge.svg"> |
10 | 13 | </a> |
11 | | - <a href="https://jcristharif.com/msgspec/"> |
| 14 | + <a href="https://nightsailer.github.io/msgspec-x/"> |
12 | 15 | <img src="https://img.shields.io/badge/docs-latest-blue.svg"> |
13 | 16 | </a> |
14 | | - <a href="https://github.com/jcrist/msgspec/blob/main/LICENSE"> |
15 | | - <img src="https://img.shields.io/github/license/jcrist/msgspec.svg"> |
| 17 | + <a href="https://github.com/nightsailer/msgspec-x/blob/main/LICENSE"> |
| 18 | + <img src="https://img.shields.io/github/license/nightsailer/msgspec-x.svg"> |
16 | 19 | </a> |
17 | | - <a href="https://pypi.org/project/msgspec/"> |
18 | | - <img src="https://img.shields.io/pypi/v/msgspec.svg"> |
| 20 | + <a href="https://pypi.org/project/msgspec-x/"> |
| 21 | + <img src="https://img.shields.io/pypi/v/msgspec-x.svg"> |
19 | 22 | </a> |
20 | | - <a href="https://anaconda.org/conda-forge/msgspec"> |
21 | | - <img src="https://img.shields.io/conda/vn/conda-forge/msgspec.svg"> |
| 23 | + <a href="https://anaconda.org/conda-forge/msgspec-x"> |
| 24 | + <img src="https://img.shields.io/conda/vn/conda-forge/msgspec-x.svg"> |
22 | 25 | </a> |
23 | | - <a href="https://codecov.io/gh/jcrist/msgspec"> |
24 | | - <img src="https://codecov.io/gh/jcrist/msgspec/branch/main/graph/badge.svg"> |
| 26 | + <a href="https://codecov.io/gh/nightsailer/msgspec-x"> |
| 27 | + <img src="https://codecov.io/gh/nightsailer/msgspec-x/branch/main/graph/badge.svg"> |
25 | 28 | </a> |
26 | 29 | </p> |
27 | 30 |
|
| 31 | +## Overview |
28 | 32 |
|
29 | | -`msgspec` is a *fast* serialization and validation library, with builtin |
30 | | -support for [JSON](https://json.org), [MessagePack](https://msgpack.org), |
31 | | -[YAML](https://yaml.org), and [TOML](https://toml.io). It features: |
| 33 | +`msgspec-x` is a community-driven fork of the [original msgspec library](https://jcristharif.com/msgspec/) by Jim Crist-Harif. This project was created to address the challenge of slow upstream maintenance and to provide a platform for community contributions that couldn't be timely integrated into the original project. |
32 | 34 |
|
33 | | -- 🚀 **High performance encoders/decoders** for common protocols. The JSON and |
34 | | - MessagePack implementations regularly |
35 | | - [benchmark](https://jcristharif.com/msgspec/benchmarks.html) as the fastest |
36 | | - options for Python. |
| 35 | +### Why msgspec-x? |
37 | 36 |
|
38 | | -- 🎉 **Support for a wide variety of Python types**. Additional types may be |
39 | | - supported through |
40 | | - [extensions](https://jcristharif.com/msgspec/extending.html). |
| 37 | +The original msgspec library is an excellent project, but the maintainer has limited time to review and merge community pull requests. This has resulted in valuable contributions and bug fixes being stuck in the review process. `msgspec-x` was created to: |
41 | 38 |
|
42 | | -- 🔍 **Zero-cost schema validation** using familiar Python type annotations. In |
43 | | - [benchmarks](https://jcristharif.com/msgspec/benchmarks.html) `msgspec` |
44 | | - decodes *and* validates JSON faster than |
45 | | - [orjson](https://github.com/ijl/orjson) can decode it alone. |
| 39 | +- **Accelerate community contributions**: Provide a faster path for community PRs and enhancements |
| 40 | +- **Enable rapid bug fixes**: Address issues without waiting for upstream review cycles |
| 41 | +- **Extend functionality**: Add new features that complement the original design |
| 42 | +- **Maintain compatibility**: Keep full backward compatibility with the original msgspec API |
46 | 43 |
|
47 | | -- ✨ **A speedy Struct type** for representing structured data. If you already |
48 | | - use [dataclasses](https://docs.python.org/3/library/dataclasses.html) or |
49 | | - [attrs](https://www.attrs.org), |
50 | | - [structs](https://jcristharif.com/msgspec/structs.html) should feel familiar. |
51 | | - However, they're |
52 | | - [5-60x faster](https://jcristharif.com/msgspec/benchmarks.html#benchmark-structs>) |
53 | | - for common operations. |
| 44 | +### **⚠️ IMPORTANT: Installation Notice** |
54 | 45 |
|
55 | | -All of this is included in a |
56 | | -[lightweight library](https://jcristharif.com/msgspec/benchmarks.html#benchmark-library-size) |
57 | | -with no required dependencies. |
| 46 | +**Do not install both `msgspec` and `msgspec-x` simultaneously!** They are conflicting packages that cannot coexist in the same environment. If you have the original `msgspec` installed, uninstall it first: |
| 47 | + |
| 48 | +```bash |
| 49 | +pip uninstall msgspec |
| 50 | +pip install msgspec-x |
| 51 | +``` |
58 | 52 |
|
59 | | ---- |
| 53 | +## Dual Namespace Architecture |
60 | 54 |
|
61 | | -`msgspec` may be used for serialization alone, as a faster JSON or |
62 | | -MessagePack library. For the greatest benefit though, we recommend using |
63 | | -`msgspec` to handle the full serialization & validation workflow: |
| 55 | +`msgspec-x` provides two distinct namespaces to serve different needs: |
64 | 56 |
|
65 | | -**Define** your message schemas using standard Python type annotations. |
| 57 | +### 1. `msgspec` Namespace - Full Compatibility |
| 58 | +The `msgspec` namespace maintains 100% API compatibility with the original library. All your existing code will work without any changes: |
66 | 59 |
|
67 | 60 | ```python |
68 | | ->>> import msgspec |
| 61 | +import msgspec # Drop-in replacement for original msgspec |
69 | 62 |
|
70 | | ->>> class User(msgspec.Struct): |
71 | | -... """A new type describing a User""" |
72 | | -... name: str |
73 | | -... groups: set[str] = set() |
74 | | -... email: str | None = None |
| 63 | +class User(msgspec.Struct): |
| 64 | + name: str |
| 65 | + email: str |
| 66 | + |
| 67 | +# All existing msgspec code works exactly the same |
| 68 | +user = User("alice", "alice@example.com") |
| 69 | +data = msgspec.json.encode(user) |
| 70 | +decoded = msgspec.json.decode(data, type=User) |
75 | 71 | ``` |
76 | 72 |
|
77 | | -**Encode** messages as JSON, or one of the many other supported protocols. |
| 73 | +### 2. `msgspec_x` Namespace - Extended Features |
| 74 | +The `msgspec_x` namespace provides additional functionality and enhancements not available in the original library: |
78 | 75 |
|
79 | 76 | ```python |
80 | | ->>> alice = User("alice", groups={"admin", "engineering"}) |
| 77 | +import msgspec_x # Extended features and community contributions |
| 78 | + |
| 79 | +# Extended features will be documented as they are added |
| 80 | +# This namespace allows for innovative features without breaking compatibility |
| 81 | +``` |
81 | 82 |
|
82 | | ->>> alice |
83 | | -User(name='alice', groups={"admin", "engineering"}, email=None) |
| 83 | +## Core Features |
84 | 84 |
|
85 | | ->>> msg = msgspec.json.encode(alice) |
| 85 | +`msgspec-x` inherits all the powerful features from the original msgspec library: |
86 | 86 |
|
87 | | ->>> msg |
88 | | -b'{"name":"alice","groups":["admin","engineering"],"email":null}' |
| 87 | +- 🚀 **High performance encoders/decoders** for JSON, MessagePack, YAML, and TOML |
| 88 | +- 🎉 **Support for a wide variety of Python types** with extension capabilities |
| 89 | +- 🔍 **Zero-cost schema validation** using Python type annotations |
| 90 | +- ✨ **Fast Struct type** for structured data representation |
| 91 | +- 📦 **Lightweight library** with no required dependencies |
| 92 | + |
| 93 | +All protocols and performance characteristics are maintained from the original implementation. |
| 94 | + |
| 95 | +## Quick Start |
| 96 | + |
| 97 | +### Installation |
| 98 | + |
| 99 | +```bash |
| 100 | +pip install msgspec-x |
89 | 101 | ``` |
90 | 102 |
|
91 | | -**Decode** messages back into Python objects, with optional schema validation. |
| 103 | +### Basic Usage |
| 104 | + |
| 105 | +Define your message schemas using standard Python type annotations: |
92 | 106 |
|
93 | 107 | ```python |
94 | | ->>> msgspec.json.decode(msg, type=User) |
95 | | -User(name='alice', groups={"admin", "engineering"}, email=None) |
| 108 | +import msgspec |
96 | 109 |
|
97 | | ->>> msgspec.json.decode(b'{"name":"bob","groups":[123]}', type=User) |
98 | | -Traceback (most recent call last): |
99 | | - File "<stdin>", line 1, in <module> |
100 | | -msgspec.ValidationError: Expected `str`, got `int` - at `$.groups[0]` |
| 110 | +class User(msgspec.Struct): |
| 111 | + """A new type describing a User""" |
| 112 | + name: str |
| 113 | + groups: set[str] = set() |
| 114 | + email: str | None = None |
101 | 115 | ``` |
102 | 116 |
|
103 | | -`msgspec` is designed to be as performant as possible, while retaining some of |
104 | | -the nicities of validation libraries like |
105 | | -[pydantic](https://pydantic-docs.helpmanual.io/). For supported types, |
106 | | -encoding/decoding a message with `msgspec` can be |
107 | | -[~10-80x faster than alternative libraries](https://jcristharif.com/msgspec/benchmarks.html). |
| 117 | +Encode messages as JSON or other supported protocols: |
| 118 | + |
| 119 | +```python |
| 120 | +alice = User("alice", groups={"admin", "engineering"}) |
| 121 | +msg = msgspec.json.encode(alice) |
| 122 | +# Output: b'{"name":"alice","groups":["admin","engineering"],"email":null}' |
| 123 | +``` |
| 124 | + |
| 125 | +Decode messages back into Python objects with schema validation: |
| 126 | + |
| 127 | +```python |
| 128 | +# Successful decoding |
| 129 | +user = msgspec.json.decode(msg, type=User) |
| 130 | + |
| 131 | +# Validation error example |
| 132 | +msgspec.json.decode(b'{"name":"bob","groups":[123]}', type=User) |
| 133 | +# Raises: ValidationError: Expected `str`, got `int` - at `$.groups[0]` |
| 134 | +``` |
| 135 | + |
| 136 | +## Performance |
| 137 | + |
| 138 | +`msgspec-x` maintains the same exceptional performance characteristics as the original msgspec library. In benchmarks, it can be 10-80x faster than alternative libraries for encoding/decoding with validation. |
108 | 139 |
|
109 | 140 | <p align="center"> |
110 | 141 | <a href="https://jcristharif.com/msgspec/benchmarks.html"> |
111 | 142 | <img src="https://raw.githubusercontent.com/jcrist/msgspec/main/docs/source/_static/bench-validation.svg"> |
112 | 143 | </a> |
113 | 144 | </p> |
114 | 145 |
|
115 | | -See [the documentation](https://jcristharif.com/msgspec/) for more information. |
| 146 | +## Community & Contributing |
| 147 | + |
| 148 | +This project welcomes community contributions! Unlike the original project, we aim to provide faster review cycles and more responsive maintenance. |
| 149 | + |
| 150 | +- 🐛 **Bug Reports**: Issues are addressed promptly |
| 151 | +- 🚀 **Feature Requests**: Community-driven feature development |
| 152 | +- 🔧 **Pull Requests**: Faster review and merge process |
| 153 | +- 📚 **Documentation**: Community-maintained documentation improvements |
| 154 | + |
| 155 | +## Documentation |
| 156 | + |
| 157 | +For detailed documentation, examples, and API references, visit: |
| 158 | +- **Project Documentation**: [https://nightsailer.github.io/msgspec-x/](https://nightsailer.github.io/msgspec-x/) |
| 159 | +- **Original msgspec docs**: [https://jcristharif.com/msgspec/](https://jcristharif.com/msgspec/) (for reference) |
| 160 | + |
| 161 | +## License |
116 | 162 |
|
| 163 | +New BSD License. See the [License File](https://github.com/nightsailer/msgspec-x/blob/main/LICENSE). |
117 | 164 |
|
118 | | -## LICENSE |
| 165 | +## Acknowledgments |
119 | 166 |
|
120 | | -New BSD. See the |
121 | | -[License File](https://github.com/jcrist/msgspec/blob/main/LICENSE). |
| 167 | +Special thanks to Jim Crist-Harif for creating the original msgspec library. This fork exists to complement and extend his excellent work, not to replace it. |
0 commit comments