Skip to content

Instantly share code, notes, and snippets.

View samuelcolvin's full-sized avatar

Samuel Colvin samuelcolvin

View GitHub Profile

Senior Frontend Developer at Pydantic

Opportunity to join Pydantic! We are looking to hire someone to lead our frontend development.

We want to hire a senior engineer who is as experienced with TypeScript, React and UI/UX as we are with Python, Rust and API design.

No recruiters or agencies please, any contact from recruiters will be marked as spam.

About Pydantic

@samuelcolvin
samuelcolvin / aicli.py
Last active March 2, 2024 16:04
OpenAI powered AI CLI in just a few lines of code - moved to https://github.com/samuelcolvin/aicli
#!/usr/bin/env python3
import os
from datetime import datetime, timezone
from pathlib import Path
from prompt_toolkit import PromptSession
from prompt_toolkit.history import FileHistory
import openai
from rich.console import Console
from rich.markdown import Markdown
@samuelcolvin
samuelcolvin / emojis.py
Created July 13, 2023 16:57
Pydantic parsing JSON and validating URLs vs. pure pyton
import timeit
import json
from urllib.parse import urlparse
import requests
from pydantic import TypeAdapter, HttpUrl
reps = 7
number = 100
r = requests.get('https://api.github.com/emojis')
import polars as pl
pl.Config.set_tbl_rows(30)
ds = pl.read_parquet('page_views.parquet').sort('ts')
path_counts = (
ds.with_columns(pl.col('path').str.replace(r'^/(latest|dev-v\d|\d\.\d+)', ''))
.groupby(pl.col('path'))
.agg([pl.count().alias('count')])
"""
pydantic-core: 01fdec6d2242fdf7205663d566be5ba990d1d459 - the custom-dataclass-validator branch
and pydantic: 519800fa5167a57681ba3b202503751aa0f17347 - the dataclasses-v2 branch
"""
from typing import TypeVar
import pytest
from pydantic import BaseModel, ValidationError
@samuelcolvin
samuelcolvin / python-people.md
Last active August 29, 2025 11:09
An incomplete list of people in the Python community to follow on Twitter and Mastodon.

Python People

(Updated 2022-11-16 with suggestions from comments below, Twitter and Mastodon)

An incomplete list of people in the Python community to follow on Twitter and Mastodon.

With the risk that Twitter dies, I'd be sad to lose links to interesting people in the community, hence this list.

I would love you to comment below with links to people I've missed.

@samuelcolvin
samuelcolvin / insert_assert.py
Last active May 10, 2023 17:45
auto-generate assert statements in pytest
"""
License: MIT
Copyright (c) 2022 Samuel Colvin.
See https://twitter.com/adriangb01/status/1573708407479189505
## Usage
Once installed just add
require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeHTML = exports.decodeHTMLStrict = exports.decodeXML = void 0;
var entities_json_1 = __importDefault(require("./maps/entities.json"));
var legacy_json_1 = __importDefault(require("./maps/legacy.json"));
var xml_json_1 = __importDefault(require("./maps/xml.json"));
@samuelcolvin
samuelcolvin / README.md
Last active September 15, 2022 14:42
Check version script used before release.

To use simply run

VERSION_PATH='<your package dir>/version.py' python <(curl -Ls https://gist.githubusercontent.com/samuelcolvin/4e1ad439c5489e8d6478cdee3eb952ef/raw/check_version.py)
import asyncio
import base64
import json
from pathlib import Path
from httpx import AsyncClient
from bs4 import BeautifulSoup
from devtools import debug
START_URL = 'https://github.com/pydantic/pydantic/network/dependents'