|
6 | 6 | [](https://github.com/pydantic/pydantic-core) |
7 | 7 | [](https://github.com/pydantic/pydantic-core/blob/main/LICENSE) |
8 | 8 |
|
9 | | -This package provides the core functionality for [pydantic](https://docs.pydantic.dev) validation and serialization. |
| 9 | +This repository is the (archived) original home of `pydantic-core`, which is a key piece of Pydantic >= 2. It now resides inside the main `pydantic` repository. |
10 | 10 |
|
11 | | -Pydantic-core is currently around 17x faster than pydantic V1. |
12 | | -See [`tests/benchmarks/`](./tests/benchmarks/) for details. |
13 | | - |
14 | | -## Example of direct usage |
15 | | - |
16 | | -_NOTE: You should not need to use pydantic-core directly; instead, use pydantic, which in turn uses pydantic-core._ |
17 | | - |
18 | | -```py |
19 | | -from pydantic_core import SchemaValidator, ValidationError |
20 | | - |
21 | | - |
22 | | -v = SchemaValidator( |
23 | | - { |
24 | | - 'type': 'typed-dict', |
25 | | - 'fields': { |
26 | | - 'name': { |
27 | | - 'type': 'typed-dict-field', |
28 | | - 'schema': { |
29 | | - 'type': 'str', |
30 | | - }, |
31 | | - }, |
32 | | - 'age': { |
33 | | - 'type': 'typed-dict-field', |
34 | | - 'schema': { |
35 | | - 'type': 'int', |
36 | | - 'ge': 18, |
37 | | - }, |
38 | | - }, |
39 | | - 'is_developer': { |
40 | | - 'type': 'typed-dict-field', |
41 | | - 'schema': { |
42 | | - 'type': 'default', |
43 | | - 'schema': {'type': 'bool'}, |
44 | | - 'default': True, |
45 | | - }, |
46 | | - }, |
47 | | - }, |
48 | | - } |
49 | | -) |
50 | | - |
51 | | -r1 = v.validate_python({'name': 'Samuel', 'age': 35}) |
52 | | -assert r1 == {'name': 'Samuel', 'age': 35, 'is_developer': True} |
53 | | - |
54 | | -# pydantic-core can also validate JSON directly |
55 | | -r2 = v.validate_json('{"name": "Samuel", "age": 35}') |
56 | | -assert r1 == r2 |
57 | | - |
58 | | -try: |
59 | | - v.validate_python({'name': 'Samuel', 'age': 11}) |
60 | | -except ValidationError as e: |
61 | | - print(e) |
62 | | - """ |
63 | | - 1 validation error for model |
64 | | - age |
65 | | - Input should be greater than or equal to 18 |
66 | | - [type=greater_than_equal, context={ge: 18}, input_value=11, input_type=int] |
67 | | - """ |
68 | | -``` |
69 | | - |
70 | | -## Getting Started |
71 | | - |
72 | | -### Prerequisites |
73 | | - |
74 | | -You'll need: |
75 | | -1. **[Rust](https://rustup.rs/)** - Rust stable (or nightly for coverage) |
76 | | -2. **[uv](https://docs.astral.sh/uv/getting-started/installation/)** - Fast Python package manager (will install Python 3.9+ automatically) |
77 | | -3. **[git](https://git-scm.com/)** - For version control |
78 | | -4. **[make](https://www.gnu.org/software/make/)** - For running development commands (or use `nmake` on Windows) |
79 | | - |
80 | | -### Quick Start |
81 | | - |
82 | | -```bash |
83 | | -# Clone the repository (or from your fork) |
84 | | -git clone git@github.com:pydantic/pydantic-core.git |
85 | | -cd pydantic-core |
86 | | - |
87 | | -# Install all dependencies using uv, setup pre-commit hooks, and build the development version |
88 | | -make install |
89 | | -``` |
90 | | - |
91 | | -Verify your installation by running: |
92 | | - |
93 | | -```bash |
94 | | -make |
95 | | -``` |
96 | | - |
97 | | -This runs a full development cycle: formatting, building, linting, and testing |
98 | | - |
99 | | -### Development Commands |
100 | | - |
101 | | -Run `make help` to see all available commands, or use these common ones: |
102 | | - |
103 | | -```bash |
104 | | -make build-dev # to build the package during development |
105 | | -make build-prod # to perform an optimised build for benchmarking |
106 | | -make test # to run the tests |
107 | | -make testcov # to run the tests and generate a coverage report |
108 | | -make lint # to run the linter |
109 | | -make format # to format python and rust code |
110 | | -make all # to run to run build-dev + format + lint + test |
111 | | -``` |
112 | | - |
113 | | -### Useful Resources |
114 | | - |
115 | | -* [`python/pydantic_core/_pydantic_core.pyi`](./python/pydantic_core/_pydantic_core.pyi) - Python API types |
116 | | -* [`python/pydantic_core/core_schema.py`](./python/pydantic_core/core_schema.py) - Core schema definitions |
117 | | -* [`tests/`](./tests) - Comprehensive usage examples |
118 | | - |
119 | | -## Profiling |
120 | | - |
121 | | -It's possible to profile the code using the [`flamegraph` utility from `flamegraph-rs`](https://github.com/flamegraph-rs/flamegraph). (Tested on Linux.) You can install this with `cargo install flamegraph`. |
122 | | - |
123 | | -Run `make build-profiling` to install a release build with debugging symbols included (needed for profiling). |
124 | | - |
125 | | -Once that is built, you can profile pytest benchmarks with (e.g.): |
126 | | - |
127 | | -```bash |
128 | | -flamegraph -- pytest tests/benchmarks/test_micro_benchmarks.py -k test_list_of_ints_core_py --benchmark-enable |
129 | | -``` |
130 | | -The `flamegraph` command will produce an interactive SVG at `flamegraph.svg`. |
131 | | - |
132 | | -## Releasing |
133 | | - |
134 | | -1. Bump package version locally. Do not just edit `Cargo.toml` on Github, you need both `Cargo.toml` and `Cargo.lock` to be updated. |
135 | | -2. Make a PR for the version bump and merge it. |
136 | | -3. Go to https://github.com/pydantic/pydantic-core/releases and click "Draft a new release" |
137 | | -4. In the "Choose a tag" dropdown enter the new tag `v<the.new.version>` and select "Create new tag on publish" when the option appears. |
138 | | -5. Enter the release title in the form "v<the.new.version> <YYYY-MM-DD>" |
139 | | -6. Click Generate release notes button |
140 | | -7. Click Publish release |
141 | | -8. Go to https://github.com/pydantic/pydantic-core/actions and ensure that all build for release are done successfully. |
142 | | -9. Go to https://pypi.org/project/pydantic-core/ and ensure that the latest release is published. |
143 | | -10. Done 🎉 |
| 11 | +See the current `pydantic-core` code at https://github.com/pydantic/pydantic/tree/main/pydantic-core |
0 commit comments