{"id":28417461,"url":"https://github.com/ua-parser/uap-clj","last_synced_at":"2025-06-26T03:31:42.348Z","repository":{"id":40773319,"uuid":"45234217","full_name":"ua-parser/uap-clj","owner":"ua-parser","description":"Clojure language implementation of ua-parser","archived":false,"fork":false,"pushed_at":"2023-04-20T22:58:35.000Z","size":125,"stargazers_count":7,"open_issues_count":0,"forks_count":5,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-21T03:04:55.550Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ua-parser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-10-30T06:51:40.000Z","updated_at":"2024-08-02T02:20:04.000Z","dependencies_parsed_at":"2023-09-24T09:17:32.403Z","dependency_job_id":null,"html_url":"https://github.com/ua-parser/uap-clj","commit_stats":{"total_commits":83,"total_committers":6,"mean_commits":"13.833333333333334","dds":0.1686746987951807,"last_synced_commit":"209470366ea0b10b1de8bf2bb80e5d59375b3770"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ua-parser/uap-clj","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ua-parser%2Fuap-clj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ua-parser%2Fuap-clj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ua-parser%2Fuap-clj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ua-parser%2Fuap-clj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ua-parser","download_url":"https://codeload.github.com/ua-parser/uap-clj/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ua-parser%2Fuap-clj/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261994172,"owners_count":23241949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-06-04T05:43:21.058Z","updated_at":"2025-06-26T03:31:42.328Z","avatar_url":"https://github.com/ua-parser.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# uap-clj\n\n[![CircleCI](https://circleci.com/gh/russellwhitaker/uap-clj.svg?style=svg)](https://circleci.com/gh/russellwhitaker/uap-clj)\n\nA [`ua-parser/uap-core`](https://github.com/ua-parser/uap-core) based Clojure library for extracting browser, operating system, and device information from a raw useragent string.\n\nThis library is also used by an Apache Hadoop Hive Simple UDF, [`uap-clj-hiveudf`](https://github.com/russellwhitaker/uap-clj-hiveudf), and an Amazon AWS Lambda function, [`uap-clj-lambda`](https://github.com/russellwhitaker/uap-clj-lambda).\n\nFor Java programmers, an API is provided as well, allowing direct use in native Java code (see below.)\n\nThe canonical version of this project lives at [`russellwhitaker/uap-clj`](https://github.com/russellwhitaker/uap-clj) and is mirrored at [`ua-parser/uap-clj`](https://github.com/ua-parser/uap-clj).\n\n## Setup\n\nAdd this to the `:dependencies` stanza of your `project.clj`:\n\n[![Clojars Project](http://clojars.org/uap-clj/latest-version.svg)](http://clojars.org/uap-clj)\n\n`uap-clj` depends on the file `regexes.yaml` actively maintained in the public [`ua-parser/uap-core`](https://github.com/ua-parser/uap-core) repository, as well as on the test fixtures `test_ua.yaml`, `test_os.yaml`, and `test_device.yaml` contained therein. Be sure to run `rm -rf .lein-get-deps \u0026\u0026 lein git-deps \u0026\u0026 lein deps` after cloning this code repository, and re-run on occasion to pull in changes committed to those `uap-core` assets.\n\n`uap-clj` needs `regexes.yaml` in `edn` format. One way do this conversion is to run:\n\n``` bash\nuap-clj$ cat src/resources/submodules/regexes.yaml | jet -i yaml -o edn -k \u003e resources/regexes.edn\n```\n\nInstall [jet](https://github.com/borkdude/jet) CLI:\n\n``` bash\n\nbrew install borkdude/brew/jet\n```\n\nConverting the regexes.yaml file to native Clojure EDN data format removes the runtime clj-yaml dependency.\n\nTo generate your classes and .jar files:\n\n```bash\n→ lein build\nCompiling uap-clj.browser\nCompiling uap-clj.common\nCompiling uap-clj.core\nCompiling uap-clj.device\nCompiling uap-clj.java.api.browser\nCompiling uap-clj.java.api.device\nCompiling uap-clj.java.api.os\nCompiling uap-clj.os\nCreated /Users/whitaker/dev/ua-parser/uap-clj/target/uap-clj-1.7.0.jar\nCreated /Users/whitaker/dev/ua-parser/uap-clj/target/uap-clj-1.7.0-standalone.jars\n```\n\n### Java dependencies\n\nThis code was originally tested and shown to run under Java 7, and hasn't broken yet through Java 16:\n\n```bash\n→ java -version\nopenjdk version \"17.0.7\" 2023-04-18\nOpenJDK Runtime Environment Temurin-17.0.7+7 (build 17.0.7+7)\nOpenJDK 64-Bit Server VM Temurin-17.0.7+7 (build 17.0.7+7, mixed mode, sharing)s\n```\n\n## Development\n### Running the test suite\n\nThis project uses [`speclj`](http://speclj.com). The core test suite comprises almost entirely test generators built from reading in test fixtures from the [`ua-parser/uap-core`](https://github.com/ua-parser/uap-core) repository, which themselves are pulled into the local workspace as dependencies using [`tobyhede/lein-git-deps`](https://github.com/tobyhede/lein-git-deps).\n\n```bash\n→ lein test\n\nFinished in 0.26248 seconds\n112663 examples, 0 failuress\n```\nThe test suite runs against all the browser, o/s, and device YAML fixtures in [`ua-parser/uap-core/tests`](https://github.com/ua-parser/uap-core/blob/master/tests), for both the native Clojure core library and the Java API. The `clojars` artifact is compiled with these fixtures linked as a git submodule dependency.\n\n## Use / Production\n\nThe basic utility functions of this library comprise `useragent`, `browser`, `os`, and `device`; memoized versions of the same functions are provided as conveniences for production environments where a requirement for low latency response from large numbers of rapidly repeated requests is worth the memory penalty incurred by the need to maintain a growing cache of input/output value mappings. Accordingly, these functions are named `useragent-memoized`, `browser-memoized`, `os-memoized`, and `device-memoized`.\n\n### Commandline (CLI)\n\n```bash\n/usr/bin/java -jar uap-clj-1.7.0-standalone.jar \u003cinput_filename\u003e [\u003coptional_out_filename\u003e]\n```\n\nThis command takes as its first argument the name of a text file containing one useragent per line, and prints a TSV (tab-separated) file - defaulting to `useragent_lookup.tsv` - with this line format:\n\n`useragent string\u003ctab\u003ebrowser family\u003ctab\u003ebrowser major\u003ctab\u003ebrowser minor\u003ctab\u003ebrowser patch\u003ctab\u003eos family\u003ctab\u003eos major\u003ctab\u003eos minor\u003ctab\u003eos patch\u003ctab\u003eos patch_minor\u003ctab\u003edevice family\u003ctab\u003edevice brand\u003ctab\u003edevice model\u003cnewline\u003e`\n\nThe output file has a single-line header and can be be trivially imported by your favorite spreadsheet or database ETL tool.\n\nA Leiningen-based run option is available as well, which is particularly convenient during development:\n\n```bash\nlein run \u003cinput_filename\u003e [\u003coptional_out_filename\u003e]\n```\n\nNote that these instructions assume you're using the standalone version of the project .jar file, for development \u0026 portability: this will get you running quickly, but it's almost always a better thing to use the mininal jarfile instead, since it _doesn't_ pull in 4Mb of dependencies. To enable this, you'll need to install prerequisite dependencies (specified in `project.clj`) on your classpath.\n\n### In a Clojure REPL\n\nIf you'd like to explore useragent data interactively, and you have Leiningen installed, you can do this:\n\n```clojure\n$ lein repl\nnREPL server started on port 54100 on host 127.0.0.1 - nrepl://127.0.0.1:54100\nREPL-y 0.4.4, nREPL 0.8.3\nClojure 1.11.1\nOpenJDK 64-Bit Server VM 17.0.7+7\n    Docs: (doc function-name-here)\n          (find-doc \"part-of-name-here\")\n  Source: (source function-name-here)\n Javadoc: (javadoc java-object-or-class-here)\n    Exit: Control+D or (exit) or (quit)\n Results: Stored in vars *1, *2, *3, an exception in *e\n\nmy-project.core=\u003e (require `[uap-clj.core :as u])\nnil\nmy-project.core=\u003e (def my-useragent \"Lenovo-A288t_TD/S100 Linux/2.6.35 Android/2.3.5 Release/02.29.2012 Browser/AppleWebkit533.1 Mobile Safari/533.1 FlyFlow/1.4\")\n#'my-project.core/my-useragent\nmy-project.core=\u003e (pprint (u/useragent my-useragent))\n{:ua\n \"Lenovo-A288t_TD/S100 Linux/2.6.35 Android/2.3.5 Release/02.29.2012 Browser/AppleWebkit533.1 Mobile Safari/533.1 FlyFlow/1.4\",\n :browser\n {:family \"Baidu Explorer\", :major \"1\", :minor \"4\", :patch \"\"},\n :os\n {:family \"Android\",\n  :major \"2\",\n  :minor \"3\",\n  :patch \"5\",\n  :patch_minor \"\"},\n :device\n {:family \"Lenovo A288t_TD\", :brand \"Lenovo\", :model \"A288t_TD\"}}\nnil\n```\n\nIf you only care about particular `browser`, `os`, or `device` values, you can look each of these separately:\n\n```clojure\nuap-clj.core=\u003e (browser my-useragent)\n{:family \"Baidu Explorer\", :major \"1\", :minor \"4\", :patch \"\"}\nuap-clj.core=\u003e (os my-useragent)\n{:family \"Android\", :major \"2\", :minor \"3\", :patch \"5\", :patch_minor \"\"}\nuap-clj.core=\u003e (device my-useragent)\n{:family \"Lenovo A288t_TD\", :brand \"Lenovo\", :model \"A288t_TD\"}\n```\n\nUnknown useragents are classified \"Other\":\n\n```clojure\nuap-clj.core=\u003e (pprint (useragent \"Some unknown useragent we've not yet categorized/v0.2.0/yomama@yamama.co.jp\"))\n{:ua\n \"Some unknown useragent we've not yet categorized/v0.2.0/yomama@yamama.co.jp\",\n :browser {:family \"Other\", :patch nil, :major nil, :minor nil},\n :os\n {:patch_minor nil,\n  :family \"Other\",\n  :patch nil,\n  :major nil,\n  :minor nil},\n :device {:family \"Other\", :brand nil, :model nil}}\nnil\nuap-clj.core=\u003e\n```\nYou can also use any other Clojure REPL for the same type of interactive data exploration.\n\n### In a RESTful API\n\nIf you have an Heroku account, [you can easily deploy a Compojure app there](https://devcenter.heroku.com/articles/getting-started-with-clojure) using GET and POST routes that look something like this:\n\n```clojure\n(defroutes app\n  (GET \"/ua\" {{input :input} :params}\n       {:status 200\n        :headers {\"Content-Type\" \"text/plain\"}\n        :body (pr-str (useragent input))})\n  (POST \"/\" {{ua :ua} :params}\n       {:status 200\n        :headers {\"Content-Type\" \"text/plain\"}\n        :body (pr-str (useragent ua))})\n  (ANY \"*\" []\n       (route/not-found (slurp (io/resource \"404.html\")))))\n```\nAll you need to enable the use of the `lookup-useragent` function here is to add `[uap-clj \"1.7.0\"]` to the `:dependencies` vector in your Compojure app's `project.clj` (or a similar entry to `deps.edn` if you're using a more modern `tools-deps` toolchain), and `[uap-clj.core :refer [lookup-useragent]]` to the `:require` vector of your `web.clj`. Then you can do this type of thing after deployment:\n\n```bash\n→ curl --data \"ua=AppleCoreMedia/1.0.0.12F69 (Apple TV; U; CPU OS 8_3 like Mac OS X; en_us)\" http://\u003cyour_app\u003e.herokuapp.com {:ua \"AppleCoreMedia/1.0.0.12F69 (Apple TV; U; CPU OS 8_3 like Mac OS X; en_us)\", :browser {:family \"Other\", :patch nil, :major nil, :minor nil}, :os {:family \"ATV OS X\", :major \"\", :minor \"\", :patch \"\", :patch_minor \"\"}, :device {:family \"AppleTV\", :brand \"Apple\", :model \"AppleTV\"}}\n```\n\n### In native Java projects\n\nAdd this repository to your `pom.xml`:\n\n```xml\n\u003crepository\u003e\n  \u003cid\u003eclojars\u003c/id\u003e\n  \u003curl\u003ehttp://clojars.org/repo/\u003c/url\u003e\n\u003c/repository\u003e\n```\n\nThen add these dependencies to your `pom.xml`:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.clojure\u003c/groupId\u003e\n  \u003cartifactId\u003eclojure\u003c/artifactId\u003e\n  \u003cversion\u003e1.11.1\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003euap-clj\u003c/groupId\u003e\n  \u003cartifactId\u003euap-clj\u003c/artifactId\u003e\n  \u003cversion\u003e1.7.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nExample usage:\n\n```java\npackage useragent;\n\nimport java.util.HashMap;\n\n// Java API for uap-clj Clojure implementation of useragent parser\nimport uap_clj.java.api.*;\n\npublic class Parser {\n  public Parser() {};\n\n  public static void main(String[] args) {\n    String ua = args[0];\n\n    HashMap b = Browser.lookup(ua);\n    HashMap o = OS.lookup(ua);\n    HashMap d = Device.lookup(ua);\n\n    System.out.println(\"Browser family: \" + b.get(\"family\"));\n    System.out.println(\"Browser major number: \" + b.get(\"major\"));\n    System.out.println(\"Browser minor number: \" + b.get(\"minor\"));\n    System.out.println(\"Browser patch number: \" + b.get(\"patch\"));\n\n    System.out.println(\"O/S family: \" + o.get(\"family\"));\n    System.out.println(\"O/S major number: \" + o.get(\"major\"));\n    System.out.println(\"O/S minor number: \" + o.get(\"minor\"));\n    System.out.println(\"O/S patch number: \" + o.get(\"patch\"));\n    System.out.println(\"O/S patch_minor number: \" + o.get(\"patch_minor\"));\n\n    System.out.println(\"Device family: \" + d.get(\"family\"));\n    System.out.println(\"Device brand: \" + d.get(\"brand\"));\n    System.out.println(\"Device model: \" + d.get(\"model\"));\n  }\n}\n```\n\n```bash\n→ mvn compile\n→ mvn exec:java -Dexec.mainClass=\"useragent.Parser\" -Dexec.args=\"'Lenovo-A288t_TD/S100 Linux/2.6.35 Android/2.3.5 Release/02.29.2012 Browser/AppleWebkit533.1 Mobile Safari/533.1 FlyFlow/1.4'\"\n[INFO] Scanning for projects...\n[INFO]\n[INFO] ------------------------------------------------------------------------\n[INFO] Building UapJavaWrapper 1.0-SNAPSHOT\n[INFO] ------------------------------------------------------------------------\n[INFO]\n[INFO] --- exec-maven-plugin:1.7.0:java (default-cli) @ UapJavaWrapper ---\nBrowser family: Baidu Explorer\nBrowser major number: 1\nBrowser minor number: 4\nBrowser patch number:\nO/S family: Android\nO/S major number: 2\nO/S minor number: 3\nO/S patch number: 5\nO/S patch_minor number:\nDevice family: Lenovo A288t_TD\nDevice brand: Lenovo\nDevice model: A288t_TD\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time: 1.961 s\n[INFO] Finished at: 2023-04-10T14:39:45-08:00\n[INFO] Final Memory: 15M/301M\n[INFO] ------------------------------------------------------------------------\n```\n\n## Future / Enhancements\n\n* add option to source `regexes.yaml` from an S3 bucket\n* replace `speclj` with `clojure.test`\n* add `clojure.spec`\n\n__Maintained by Russell Whitaker__\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015-2023 Russell Whitaker\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fua-parser%2Fuap-clj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fua-parser%2Fuap-clj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fua-parser%2Fuap-clj/lists"}