Craftopia
Steam achievements and progress for Craftopia - 0.0% complete with 0/50 achievements unlocked.
global Field
global BaseModel
from pydantic import BaseModel
from pydantic import Field
Pydantic is a Python library for serializing data into models that can be validated with a deep set of built in valitators or your own custom validators, and deserialize back to JSON or dictionary.
Installation #
To install pydantic you will first need python and pip. Once you have pip installed you can install pydantic with pip.
pip install pydantic
Always install in a virtual environment
Creating a Pydantic model #
To get started with pydantic you will first need to create a Pydantic model.
This is a python class that inherits from pydantic.BaseModel.
from pydantic import BaseModel
from pydantic import Field
from typing import Optional
class Person(BaseModel):
name: str = Field(...)
age: int
parsing an object #
person = Person(name="John Doe", age=30)
print(person)
name='John Doe' age=30
data serialization #
Pydantic has some very robust serialization methods that will automatically coherse your data into the type specified by the type-hint in the model if it can.
person = Person(name=12, age="30")
print(f'name: {person.name}, type: {type(person.name)}')
print(f'age: {person.age}, type: {type(person.age)}')
1 validation error for Person
name
Input should be a valid string [type=string_type, input_value=12, input_type=int]
For further information visit https://errors.pydantic.dev/2.3/v/string_type
person = Person(name="John Doe", age='thirty')
print(f'name: {person.name}, type: {type(person.name)}')
print(f'age: {person.age}, type: {type(person.age)}')
1 validation error for Person
age
Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='thirty', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/int_parsing
loading from json #
serializing to json #
validation #
Knockout City™
Steam achievements and progress for Knockout City™ - 2.0% complete with 1/50 achievements unlocked.
Badger
Steam achievements and progress for Badger - 12.5% complete with 5/40 achievements unlocked.
Frozen Flame
Steam achievements and progress for Frozen Flame - 6.25% complete with 2/32 achievements unlocked.
MultiVersus
Steam achievements and progress for MultiVersus - 53.57% complete with 15/28 achievements unlocked.
useful btrfs tools
Subnautica
Steam achievements and progress for Subnautica - 5.88% complete with 1/17 achievements unlocked.
Poly Bridge
Steam achievements and progress for Poly Bridge - 9.09% complete with 2/22 achievements unlocked.
devops philosophy
Steep
Steam achievements and progress for Steep - 0.0% complete with 0/41 achievements unlocked.
extending vim with shell commands
from kedro.pipeline import node
node(
input="raw",
output="int",
func=my_func,
tags=["one"],
)
- 11ty https://www.rockyourcode.com/how-to-deploy-eleventy-to-github-pages-with-github-actions/
- hugo puts it in the base url https://gohugo.io/getting-started/configuration/#baseurl
- mkdocs uses a special cli build command https://squidfunk.github.io/mkdocs-material/publishing-your-site/#github-pages
Upon first running an aws cli command using localstack you might end up with the following error.
Unable to locate credentials. You can configure credentials by running "aws configure".
Easy way #
The easy easiest way is to leverage a package called awscli-local.
pipx install awscli-local
Leveraging the awscli #
If you want to use the cli pro
pipx install awscli
aws config --profile localstack
# put what you want for the keys, but enter a valid region like us-east-1
alias aws='aws --endpoint-url http://localhost:4566 --profile localstack'
npx create-react-app todoreact
import React,{useState,useEffect} from 'react';
import './App.css';
function App() {
const [data,setData]=useState([]);
const [newName,setNewName]=useState([]);
const getData=()=>{
fetch('/api'
,{
headers : {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
}
)
.then(function(response){
return response.json();
})
.then(function(myJson) {
setData(myJson)
});
}
useEffect(()=>{
getData()
},[])
const addItem= async () => {
const rawResponse = await fetch('/api/add/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"name": newName})
});
const content = await rawResponse;
console.log(content);
getData()
}
return (
<div className="App">
{
data && data.length>0 && data.map((item)=><p>{item.id}{item.priority}{item.name}<button>raise priority</button></p>)
}
<input type='text' value={newName} onChange={(e) => (setNewName(e.target.value))} />
<button onClick={addItem} >add item</button>
</div>
);
}
export default App;
Hatch allows you to specify direct references for dependencies in your
pyproject.toml file. This is useful when you want to depend on a package that
is not available on PyPI or when you want to use a specific version from a Git
repository. Often used for unreleased packages, or unreleased versions of
packages.
[project]
dependencies = ['markata', 'markata-todoui@git+https://github.com/waylonwalker/markata-todoui']
[tool.hatch.metadata]
allow-direct-references=true
