{"id":39188994,"url":"https://github.com/chalk-ai/examples","last_synced_at":"2026-01-17T22:41:27.566Z","repository":{"id":87109108,"uuid":"513721842","full_name":"chalk-ai/examples","owner":"chalk-ai","description":"Curated examples and patterns for using Chalk. Use these to build your feature pipelines.","archived":false,"fork":false,"pushed_at":"2025-12-10T16:07:13.000Z","size":1145,"stargazers_count":25,"open_issues_count":8,"forks_count":5,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-12-11T01:27:02.992Z","etag":null,"topics":["chalk","data","data-science","ml","ml-ops","pipeline","python"],"latest_commit_sha":null,"homepage":"https://chalk.ai","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chalk-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-07-14T01:33:54.000Z","updated_at":"2025-12-10T16:07:18.000Z","dependencies_parsed_at":"2023-12-23T22:07:33.530Z","dependency_job_id":"50813d9e-7d02-4026-b94f-bde0a9bc57ca","html_url":"https://github.com/chalk-ai/examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chalk-ai/examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk-ai%2Fexamples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk-ai%2Fexamples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk-ai%2Fexamples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk-ai%2Fexamples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chalk-ai","download_url":"https://codeload.github.com/chalk-ai/examples/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk-ai%2Fexamples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28521165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T22:11:28.393Z","status":"ssl_error","status_checked_at":"2026-01-17T22:11:27.841Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["chalk","data","data-science","ml","ml-ops","pipeline","python"],"created_at":"2026-01-17T22:41:27.017Z","updated_at":"2026-01-17T22:41:27.556Z","avatar_url":"https://github.com/chalk-ai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Examples\n\nCurated examples and patterns for using Chalk. Use these to build your feature pipelines.\n\n## [1_features](01_features)\n\nDeclare and version features from Python.\n\n```python\n@features(owner=\"librarians@sfpl.org\")\nclass Author:\n    id: str\n    # The Author's email\n    # :tags: pii\n    name: str\n    nickname: str | None\n    books: DataFrame[Book] = has_many(lambda: Book.author_id == Author.id)\n\n@features\nclass Book:\n    id: str\n    author_id: str\n```\n\n## [2_resolvers](02_resolvers)\n\nResolvers are Python functions that compute your feature values.\nThey take as input features that they need to know to run,\nand resolve the values of one or more features. In both cases,\nyou use Python type annotations to define these dependencies and\noutputs.\n\n```python\n@online\ndef get_email_domain(email: User.email) -\u003e User.email_domain:\n    return email.split(\"@\")[1].lower()\n\n@online\ndef is_banned_email(domain: User.email_domain) -\u003e User.banned_email:\n    return domain in {\"pergi.id\", ...}\n```\n\nhttps://docs.chalk.ai/docs/resolver-overview\n\n## [3_caching](03_caching)\n\nWhen a feature is expensive or slow to compute,\nyou may wish to cache its value.\nChalk uses the terminology \"maximum staleness\"\nto describe how recently a feature value needs\nto have been computed to be returned without\nre-running a resolver.\n\nhttps://docs.chalk.ai/docs/feature-caching\n\n```python\n@features\nclass User:\n    fico_score: int = feature(max_staleness=\"30d\")\n\nChalkClient().query(\n    input={...},\n    output=[User.fico_score],\n    staleness={User.fico_score: \"10m\"},\n)\n```\n\nhttps://docs.chalk.ai/docs/feature-caching\n\n## [4_scheduling](04_scheduling)\n\nRun resolvers on a schedule, sampling values\nfor the inputs.\n\n```python\ndef only_active_filter(last_login: User.last_login, status: User.status) -\u003e bool:\n    return status == \"active\" and last_login \u003e datetime.now() - timedelta(days=30)\n\n@realtime(cron=Cron(schedule=\"29d 11h\", filter=only_active_filter))\ndef get_fico_score(name: User.name, email: User.email) -\u003e User.fico_score:\n    return requests.get(\"https://experian.com\").json()[\"score\"]\n```\n\nhttps://docs.chalk.ai/docs/resolver-cron\n\n## [5_feature_discovery](05_feature_discovery)\n\nCapture metadata to inform alerting, monitoring, and discovery.\n\n```python\n@features(owner=\"shuttle@nasa.gov\", tags=\"group:rocketry\")\nclass SpaceShuttle:\n    id: str\n\n    # The SHA1 of the software deployed to the shuttle.\n    # Should align with a git commit on main.\n    #\n    # :owner: katherine.johnson@nasa.gov\n    software_version: str\n\n    # The volume of this shuttle in square meters.\n    # :owner: architecture@nasa.gov\n    # :tags: zillow-fact, size\n    volume: str\n```\n\nhttps://docs.chalk.ai/docs/feature-discovery\n\n## [6_dataframe](06_dataframe)\n\nA Chalk DataFrame is a 2-dimensional data structure similar\nto `pandas.Dataframe`, but with richer types and\nunderlying optimizations.\n\n```python\nUser.txns[\n    Transaction.amount \u003c 0,\n    Transaction.merchant in {\"uber\", \"lyft\"} or Transaction.memo == \"uberpmts\",\n    Transaction.canceled_at is None,\n    Transaction.amount\n].sum()\n```\n\nhttps://docs.chalk.ai/docs/dataframe\n\n## [7_streaming](07_streaming)\n\nChalk gives a simple way to express streaming computations,\nfor both mapping stream and window aggregate streams.\n\n```python\n@stream(...)\ndef failed_logins(events: DataFrame[LoginMessage]) -\u003e DataFrame[\n    User.id,\n    User.num_failed_logins\n]:\n    return f\"\"\"\n        select\n          user_id as id,\n          count(*) as num_failed_logins\n        from {events}\n        where failed = 1\n        group by 1\n    \"\"\"\n```\n\nhttps://docs.chalk.ai/docs/streams\n\nhttps://docs.chalk.ai/docs/aggregations\n\n## [8_testing](08_testing)\n\nTest your Chalk features and resolvers.\n\n```python\n@realtime\ndef get_home_data(\n        hid: HomeFeatures.id,\n) -\u003e Features[HomeFeatures.price, HomeFeatures.sq_ft]:\n    return HomeFeatures(price=200_000, sq_ft=2_000)\n\ndef test_multiple_output():\n    assert get_home_data(2) == HomeFeatures(\n        price=200_000,\n        sq_ft=2_000,\n    )\n```\n\nhttps://docs.chalk.ai/docs/unit-tests\n\n## [9_github_actions](09_github_actions)\n\nDeploy feature pipelines in GitHub Actions.\n\nDocs: https://docs.chalk.ai/docs/github-actions\n\nCLI Step: https://github.com/chalk-ai/cli-action\n\nDeploy Step: https://github.com/chalk-ai/deploy-action\n\n```yaml\n- uses: chalk-ai/deploy-action@v2\n  with:\n    client-id: ${{secrets.CHALK_CLIENT_ID}}\n    client-secret: ${{secrets.CHALK_CLIENT_SECRET}}\n    await: true\n    no-promote: true\n```\n\n## [10_migrations](10_migrations)\n\nDocs on migrations coming soon!\n\n## [11_sql](11_sql)\n\nChalk can ingest your data using a SQL interface\nfrom any of the integrations that support it.\nYou can describe your queries using SQL strings\nor [SQLAlchemy](https://www.sqlalchemy.org/).\n\n```python\n@realtime\ndef get_views() -\u003e DataFrame[User]:\n    return db.query_string(\n        \"\"\"\n        select id, sum(mins) as viewed_minutes\n        from view_counts\n        group by id\n        \"\"\",\n    ).all()\n```\n\nhttps://docs.chalk.ai/docs/sql\n\n## [credit](credit)\n\nChalk can help you build insight into the financial transactions\nof your users.\n\n```python\n@realtime\ndef tradeline_rollup(\n        accounts: User.tradelines[\n            Tradeline.is_delinquent is True\n            ]\n) -\u003e User.delinquent_amount:\n    return accounts[Tradeline.outstanding].sum()\n```\n\nhttp://chalk.ai/solutions/credit\n\n## [fraud](fraud)\n\nFinding a balance between user experience and\nrisk management is a complex task for banking\nproducts. Chalk helps you express complex business\nlogic with features and resolvers, and lets data\nscientists and machine learning engineers collaborate\non solutions.\n\n```python\n@realtime(when=TransferLimit.to_account.is_internal is False)\ndef withdrawal_limit(\n        internal_accounts: TransferLimit.user.accounts[Account.is_internal is True],\n        deposits_last_90: TransferLimit.user.transfers[Transfer.from_account.is_internal is False, before(days_ago=90)],\n        user_settlement: TransferLimit.user.holdback,\n) -\u003e TransferLimit.amount:\n    ...\n\n@stream(...)\ndef agg_logins(df: DataFrame[LoginMessage]) -\u003e DataFrame[User]:\n    return f\"\"\"\n        select\n            count(*) as failed_logins,\n            user_id as id\n        from {df}\n        where status = 'failed'\n        group by id\n    \"\"\"\n```\n\nhttp://chalk.ai/solutions/fraud\n\n## [predictive_maintenance](predictive_maintenance)\n\nPredicting device failure requires complex analysis executed\nagainst a variety of data sources. Chalk's platform allows\ndata scientists to bring all the different data together,\nincluding streaming data from devices.\n\n```python\n@stream(...)\ndef process_measurements(df: DataFrame[Message]) -\u003e DataFrame[Sensor]:\n    return f\"\"\"\n        select\n            count(*) as count_failed,\n            id as device_id\n        from {df}\n        where is_failing \u003c\u003e TRUE\n        group by id\n    \"\"\"\n```\n\nhttp://chalk.ai/solutions/maintenance\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalk-ai%2Fexamples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchalk-ai%2Fexamples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalk-ai%2Fexamples/lists"}